1

I have this function in Angular 2 which works well on normal circonstances:

private callGetUserService(url: string, id: string): Observable<any> {
 return this.authHttp.get(url + id)
   .map(res => {
     return this.extractData(res);
   })
   .catch((err) => {
     console.log('Error getting account: ' + JSON.stringify(err));

     return Observable.of(err);
   });
  }

When I force a 401 response from the server, the catch(err) is always returning the err.status = 0 and err.ok = false. I am at a total loss, can anyone help?

1 Answers1

0

With the limited information provided the best help I can provide is guessing that this may be related to a CORS failed pre-flight request that only happens when you force the 401 response.


Why is that my guess?

Mostly because:

CORS Error Response Status = 0

It seems whenever a CORS request fails, the response returned is always 0.

AngularJS - $http get returns error with status 0?

You have HTTP access control (CORS) issues.


Also note that the best way to troubleshoot HTTP related problems is to look at the actual HTTP requests being performed. In a browser you quickly achieve that by using the developer tools and that would be my recommendation. Check the raw HTTP requests and see what happens differently that could cause the issue you experience.

Community
  • 1
  • 1
João Angelo
  • 56,552
  • 12
  • 145
  • 147