Set a code/status for "Network Error"
Problem
I'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!
Error Output
error message to the user.
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Solution: Set a code/status for "Network Error"
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
Trust Score
9 verifications
- 1
I'm having this issue. Can anyone help me please?
I'm having this issue. Can anyone help me please?
- 2
The server response is 401 but axios gives me this:
The server response is 401 but axios gives me this:
- 3
error --> "Network Error"
error.response --> undefined error.status --> undefined
Validation
Resolved in axios/axios GitHub issue #383. Community reactions: 133 upvotes.
Verification Summary
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep