0

I'm using the subscribe() to get values in json format. This values are displayed in screen.

The problem is in Microsoft Edge this method not works. It's returned error of HttpResponse 0. However, in Chrome and Firefox works normally.

This is my code:

if (this.machine.length === 0) {
  this.simulatorService.getAks(this.codIm, this.codCS)
    .subscribe(
      data => {
        console.log('works!');
        this.machine= data;
      },
      error => {
        console.log(error);
        this.machine= [];
      }
    );
}

So, I need use other method than .subscribe()? What?

So, what is the best way to turn my code works on Microsoft Edge?

---------- UPDATE 1 -----------

This code is my getAsks. It's a route that return a json file with some data.

  getAsks(codIm: codIm, codCS: codCS): Observable<Array<Equip>> {

    return this.http.get<Array<Equip>>(
      `${this.urlBase}v1/simulator/machine/${codIm}/${codCS}`,
      {
        headers: new HttpHeaders({
          'Content-Type': 'application/json'
        })
      });
  }
Zkk
  • 741
  • 13
  • 29
  • 2
    Would you be able to share the code of `simulatorService.getAks` and the relevant code that initializes `this.machine.length`? Perhaps make a Stackblitz demonstrating the issue. – Wrokar Jan 21 '19 at 18:27
  • I insert the `getAsks` method for better viewing. It's called in html with the click of button. – Zkk Jan 21 '19 at 19:14
  • Edge may have issues with the `Content-Type` header that you are adding. Is there any reason that you need this header on an HTTP GET request? It is not a standard header for GET. – Wrokar Jan 21 '19 at 20:40
  • It was just standardized. However, even removing the `Content-Type` still does not work on microsoft edge. Do you know what it could be? I get: `Http failure response for (unknown url): 0 Unknown Error` in my log of errors – Zkk Jan 22 '19 at 17:57
  • The kind/name of erros is correlated with `HttpErrorResponse`. It also appears in my `console` – Zkk Jan 22 '19 at 17:58
  • Have you looked at [this question](https://stackoverflow.com/questions/47180634/i-get-http-failure-response-for-unknown-url-0-unknown-error-instead-of-actu) with the same error message in Angular? It seems likely to be an error with the server and not the Angular client. – Wrokar Jan 22 '19 at 18:52

1 Answers1

0

The error invalid HttpResponse is probably because of your api not returning correct headers. So, I suggest for you to check the value of ${this.urlBase}v1/simulator/machine/${codIm}/${codCS} and if your api is handling this link correctly.

Ian Preglo
  • 421
  • 2
  • 10