HttpErrorResponse status returns 0 instead of 401

See original GitHub issue

I’m trying to build an interceptor to handle 401 requests, but even in the subscribe error function handler the status is 0. I tried setting observe: response but that didn’t help.

this.http .get<ILead>(this.leadApiUrl) .subscribe( data => { console.log('data' + data); this.company = data; }, err => { console.log(err); }) 401

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:13 (2 by maintainers)

github_iconTop GitHub Comments

14reactions
rameezramicommented, May 7, 2018

HI… after a loooooong time on it…i found the issue… its of course in server side. you need to set the CORS middle ware first then the remaining API middlewares

Wrong Code

'api' => [
            'throttle:60,1',
            'bindings',
            \Barryvdh\Cors\HandleCors::class,
        ],

Currect Code

'api' => [
            \Barryvdh\Cors\HandleCors::class,
            'throttle:60,1',
            'bindings'
        ],
14reactions
ghostcommented, Mar 8, 2018

I want to know why Chrome and FireFox can show 401 on console while Angular caught 0. Are these browsers changed 401 to 0 before browser API passed the result to js . @danwulff

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting status zero instead of 401 in the response
BTW, I'm using Angular 4.0.0 (core and http). This is the error I'm getting in the console due to the post request sent...
Read more >
Angular — How to intercept 401 err response and redirect to ...
Below is an example of listening to an http response which was sent by the app to the api and returned with status...
Read more >
HttpErrorResponse - Angular
A response that represents an error or failure, either from a non-successful HTTP status, an error while executing the request, or some other...
Read more >
401 Unauthorized - HTTP - MDN Web Docs
The HyperText Transfer Protocol (HTTP) 401 Unauthorized response status code indicates that the client request has not been completed ...
Read more >
401 Unauthorized Error: What It Is and How to Fix It
We'll show you how to diagnose and debug this error within your own application. Server- or Client-Side? All HTTP response status codes in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found