FG
๐Ÿ”Œ APIs & SDKs

Set a code/status for "Network Error"

Freshover 9 years ago
Mar 14, 20260 views
Confidence Score77%
77%

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

Canonical Fix
High Confidence Fix
74% confidence92% success rate9 verificationsLast verified Mar 14, 2026

Solution: Set a code/status for "Network Error"

Low Risk

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

74

Trust Score

9 verifications

92% success
  1. 1

    I'm having this issue. Can anyone help me please?

    I'm having this issue. Can anyone help me please?

  2. 2

    The server response is 401 but axios gives me this:

    The server response is 401 but axios gives me this:

  3. 3

    error --> "Network Error"

    error.response --> undefined error.status --> undefined

Validation

Resolved in axios/axios GitHub issue #383. Community reactions: 133 upvotes.

Verification Summary

Worked: 9
Partial: 2
Failed: 1
Last verified Mar 14, 2026

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

axioshttpapi