-
-
Notifications
You must be signed in to change notification settings - Fork 11k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Returning "Network Error" on unauthorized error (401) #4921
Comments
find any solution? |
What I understand, is that you are trying to get the status code(as integer) to then, handle or react with some event. axios.delete(userApi.deleteAsync, id, config).then((resp) => {
dispatch(fetchData(getState().user.params))
toast.success(resp.data.message)
return resp.data.data
}).catch((resp) => {
const { status } = resp.response;
//console.log(status) to check the status of response Let us know if this solves your issue. |
I still don't have a definitive solution. Occasionally I created a hack, assuming for now that all connection errors are 401, so I return an exception in this pattern. hack: if (resp.message == 'Network Error') return toast.error("You do not have permission for this action.")
I still don't have a definitive solution. Occasionally I created a hack, assuming for now that all connection errors are 401, so I return an exception in this pattern.
|
Your suggestion unfortunately did not resolve the issue. Keeps returning status code 0. My api is really blocking the connection of the axios call, so I agree that it really has to return that it is having difficulties connecting to the api, since that is exactly what is happening. However, the api when blocking the connection due to permissioning problems, it returns either a 401 or a 403, which are related to permissioning. So, I can't understand how axios can't handle this api return pattern. Anyway... Thanks and I'm still waiting for an elegant solution. |
Try to keep it simple, and avoid being redundant.
This doesnt seem like axios fault, looks like we are trying to find the status code on the wrong place of the request. |
I've already checked most of the points raised by you. Simply put, when I suspected the possible error reason, I simulated a rogue environment, and checked the api call callback through the google chrome console, that's exactly where I confirmed that the api was returning a 401 (Unauthorized), however, the api callback was not able to retrieve this status code, and as I reported above, the status code comes "0", understand? Thanks for your help so far, hope we can find the solution soon. |
Did you find a solution for this. I'm having the same problem :-( |
Not yet my friend, but we are all in the fight. A solution will soon emerge. |
It may be a back-end problem, which seems to be related to cross domain. I encountered this problem when I started CORS with spring security. |
It doesn't make sense since, cors doesn't return 401. |
Cross domain setting error will lead to 5xx 4xx request, Axios returns 0 |
I think I'm seeing the same issue as well w/ the Salesforce API... |
|
I'm having the exact same error, when having a 401 error axios returns this error
|
jasonsaayman, Can you please give us strength to close this matter? |
Duplicated on issue #5173 |
Hello friend, have you solved this problem? This problem has been bothering me for several hours. Changing the back end does not work and always returns 0 |
Axios (XMLHttpRequest) cannot get the status code if:
|
I had this issue when making a request to a dotnet API. Noticed that |
I use local-ssl-proxy to test my Next.js frontend against my .NET Core backend. In my case, the two issues I was having with axios and catch were...
run-dev.bat
index.tsx
|
If you're using .NET API, you need to ensure that .UseAuthentication() is after .UseCors(), because it is a cors issue that breaks the pipeline before the authorization (where the step returns 401) . If you want to make certain that the problems is the axios library, try to test a fetch() request direct from DevTools console. If the problems persists, is not axios problem, but a pipeline configuration problem on server side. |
this fixed the issue for me. Thanks ❤️ |
As @rodrigo-web-developer mentioned for .NET, for me using a spring backend, the problem was that by sending the response in the first filter, the cors header did not apply. I fixed this by adding the headers by hand like described here before sending the 401 https://stackoverflow.com/questions/16351849/origin-is-not-allowed-by-access-control-allow-origin-how-to-enable-cors-using |
For DELETE requests, ensure to add the
|
Thanks man. Really helped a lot. Love you! |
I recently had this issue and did a lot debugging about it. Your server should set Usually they set this CORS values for successful responses, but omit them in error responses, Thus this issue happens. *Hint for people with less knowledge about CORS issues: |
THISSS was the fix for me thankss!!! |
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
Environment
The text was updated successfully, but these errors were encountered: