Set a code/status for "Network Error"
See original GitHub issueI’m trying to detect when my server is down so that I can display an appropriate error message to the user.
In this case, axios network requests throw an error which is different from all other axios errors, as discussed here: https://github.com/mzabriskie/axios/issues/204
In my code, it seems the only way to detect this error is to check err.message:
if (err.message === "Network Error"){/*tell user the server is down*/}
This bothers me because string comparisons are a little risky; perhaps some day this message will be translated, and my code will fail.
It would be great if err.status or err.code (or err.???) were set to some documented value that we can check for in our code.
Is there any other way to detect this scenario that I’m missing? Thanks all!
Issue Analytics
- State:
- Created 7 years ago
- Reactions:72
- Comments:69 (2 by maintainers)
Top GitHub Comments
It’s in
error.response.status
.I’m having this issue. Can anyone help me please?
The server response is 401 but axios gives me this:
error --> “Network Error” error.response --> undefined error.status --> undefined