3

I have angular project built in angular 10. I am getting issue in calling api from IOS chrome browser when i turn on google translation from browser.

If i do not turn on translation it is giving me correct response for API

However when i turn on translation i am getting this error.

InvalidAccessError The object does not support the operation or argument

Error is happening only when i do translation from browser if i do translation from settings in Iphone the it is working fine.

and it is also working fine in all browsers in laptop.

If use javascript fetch function instead of angular HttpClient then it is working fine with HttpClient request is not even going to server. It is giving error even before sending request.

Ninja Turtle
  • 1,293
  • 2
  • 24
  • 50
  • Can you show us the code that handles the response? – Nate T Dec 21 '20 at 08:46
  • @NathanToulbert I am using ngx-translate module for translation and that is working with iphone language translation from settings menu. But if i do translation using chrome browser then it is causing error. though i solved it for now by disabling chrome translation. – Ninja Turtle Dec 24 '20 at 06:20
  • Which loader are you using? Consider testing with [this](https://github.com/ngx-translate/http-loader) to see if you get different results. – Nate T Dec 24 '20 at 06:53
  • I don't think that issue is related to ngx-translate as i created a fresh project without ngx translate and it is having same problem – Ninja Turtle Dec 24 '20 at 07:10
  • Where in the trace is the error? Then if it is working w/ fetch api, it almost has to be related to httpClient, no? Combining comments (and deleting old ones) to keep our own stack trace to a minimum. XD – Nate T Dec 24 '20 at 07:11
  • almost 3am here. im going to bed. I can hardly think straight. In the morning, after festivities, I will take a fresh look with mind in tact. In case we do not cross paths again, happy holidays. ----- BTW I plan to clean up my comments litter in the morning. – Nate T Dec 24 '20 at 07:35
  • @NathanToulbert Yes it is related to httpClient. If you want i will upload my sample project on github and give link here so that you can test on local. – Ninja Turtle Dec 24 '20 at 08:30

1 Answers1

4

Its because HTTPClient expects a json in response by default and when you turn on translation, its no more a json. Try receiving response like

this.http.post(this.url, body, {responseType: 'text'}).subscribe((res)=> console.log(res));

also body should be a json like

body=JSON.stringify(data);

if it prints then if you feel its not a json then map it to javascript object via your code, if it seems a json then use

JSON.parse(res);
Aakash Garg
  • 10,649
  • 2
  • 7
  • 25