question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Set a code/status for "Network Error"

See original GitHub issue

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!

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:72
  • Comments:69 (2 by maintainers)

github_iconTop GitHub Comments

156reactions
jonathan-stonecommented, Dec 13, 2016

It’s in error.response.status.

148reactions
fgiarritiellocommented, Feb 24, 2017

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

HTTP response status codes - MDN Web Docs - Mozilla
HTTP response status codes indicate whether a specific HTTP request has been successfully completed. Responses are grouped in five classes:
Read more >
HTTP Status Codes, Network and DNS Errors, and Google ...
This page describes how different HTTP status codes, network errors, and DNS errors affect Google Search. We cover the top 20 status codes...
Read more >
Response not successful: Received status code 400
When attempting to save new employee information why am I getting this message? Network error: Response not successful: Received status code 400.
Read more >
How can I get the status code from an HTTP error in Axios?
If a response has been received from the server, the error object will contain the response property: ... const HttpClient = axios.create({ baseURL:...
Read more >
Status codes in HTTP - W3C
The data sections of messages Error, Forward and redirection responses may ... this indicates that the returned metainformation is not a definitive set...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found