Returning "Network Error" on unauthorized error (401)
See original GitHub issueDescribe the issue
Axios request below is returning “Network Error”, on API’s unauthorized return.
The API is in Asp Net Core with Identity. Therefore, it is recognized that my API actually returns a 401, but my request callback is not allowing me to get this return code, so that I can handle this exception directly.
I understand that, of course, my axios request tried to connect to the server, however, the identity by default doesn’t even establish this connection in cases of unauthorized, it just returns the code 401, so I imagine that then axios returns this condition that there really was a “Network Error”, since that’s exactly what happened.
I would like an idea of how we can solve this.
This is the code for the request in question
axios.delete(userApi.deleteAsync, id, config).then((resp) => {
dispatch(fetchData(getState().user.params))
toast.success(resp.data.message)
return resp.data.data
}).catch((resp) => {
Environment
- Axios Version [0.27.2]
- Adapter [e.g. XHR/HTTP]
- Browser [e.g. Chrome, Safari]
- Browser Version [e.g. 22]
- Node.js Version [16.16.0]
- OS: [Win 10]
- Additional Library Versions [React 18.1.0, Next 12.1.6]
Issue Analytics
- State:
- Created a year ago
- Reactions:2
- Comments:16
Top Results From Across the Web
401 Error: 5 Ways to Troubleshoot and Fix It - Hostinger
The 401 Unauthorized error indicates that the server's request was not verified because it lacks valid authentication credentials for the target ...
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 >How to Fix a 401 Unauthorized Error - Lifewire
A 401 Unauthorized error means the page you were trying to see needs a valid user ID/password before you can view it.
Read more >How to Fix a 401 Unauthorized Error? - GeeksforGeeks
The 401 Unauthorized Error is an HTTP status code error that represented the request sent by the client to the server that lacks...
Read more >401 Unauthorized Error: What It Is and How to Fix It
The 401 Unauthorized Error is an HTTP response status code indicating that the client could not authenticate a request.
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
I’m having the exact same error, when having a 401 error axios returns this error I checked the 401 error with the network inspector, any way to get these status from the error?