Catch a 401
See original GitHub issueIs there a way to catch a 401 error code? I first thought I could add it to the checkStatus function but
it seems that a 401 does reject the promise.
But there is little to no information in the error object.

Am I missing something?
Issue Analytics
- State:
- Created 8 years ago
- Reactions:2
- Comments:24 (6 by maintainers)
Top Results From Across the Web
How to catch 401 error using fetch method of javascript
1. Try to get the property error. · 3. If I understand correctly from the docs, an error will not be thrown if...
Read more >How to Quickly Fix the 401 Unauthorized Error (5 Methods)
The 401 (Unauthorized) status code indicates that the request has not been applied because it lacks valid authentication credentials for the ...
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 >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 >401 Error: 5 Ways to Troubleshoot and Fix It - Hostinger
The 401 Unauthorized error is triggered by unauthenticated requests made to a WordPress web server. Learn how to identify and fix the issue....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

For anyone who will have this issue in the future
Fetch API fails only if it can’t make a request. And if it can,
fetchwill be executed successfully even if it has a bad status. For example:And here are some (not all) of the errors from Fetch API:
urllikefetch('https::://hey.com')–TypeError Failed to execute 'fetch' on 'Window': Failed to parse URL from https::://hey.com;urllikefetch('http://hey')–TypeError: Failed to fetch (GET http://hey/ net::ERR_NAME_NOT_RESOLVED);fetch('https://google.com')–TypeError: Failed to fetch (GET https://google.com/ net::ERR_NAME_RESOLUTION_FAILED)fetch('https://google.com')–TypeError: Failed to fetch (Refused to connect to 'https://google.com/' because it violates the following Content Security Policy directive: "connect-src 'self'...)fetch('https://google.com')–TypeError: Failed to fetch (Fetch API cannot load https://google.com/ has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource....)The last two cases you can fix by adding (or editing) the appropriate headers on the server, if you have an access.
@dgraham that’s not correct. Fetch seems to reject the promise on a 401. So you don’t have access to the response object