Returning "Network Error" on unauthorized error (401)
Problem
Describe 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 [code block] 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]
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Solution: Returning "Network Error" on unauthorized error (401)
> Describe 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
Trust Score
1 verification
- 1
> Describe 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 "Netw
Validation
Resolved in axios/axios GitHub issue #4921. Community reactions: 0 upvotes.
Verification Summary
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep