Skip to content
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

error.code missing on Network Error #2351

Closed
MartinMuzatko opened this issue Aug 9, 2019 · 6 comments
Closed

error.code missing on Network Error #2351

MartinMuzatko opened this issue Aug 9, 2019 · 6 comments
Projects

Comments

@MartinMuzatko
Copy link

MartinMuzatko commented Aug 9, 2019

Is your feature request related to a problem? Please describe.
To properly identify errors reliably, I'd like to be able to either compare an error with instanceof or alternatively with error.code. However, this does not exist on most of the errors.
I noticed that when defining a timeout, I get at least a 'ECONNABORTED' code.
Other errors like 404, 403 are also missing this code.

Describe the solution you'd like
I'd have for 400/500 codes the error code of the name of the error, or at least the classification ClientError or ServerError.

Describe alternatives you've considered
I can also compare the name, but now I need to compile a list of codes,names and whatnot to check whether or not I am connected.

So right now I have error.code == 'ECONNABORTED' || error.name == 'Network Error'
It would be a lot easier to consume and work with this error if I could e.g. create an array of matching error codes and just check with includes.

@wangfpp
Copy link

wangfpp commented Aug 15, 2019

@MartinMuzatko i have same issue you reslove this promble?

@MartinMuzatko
Copy link
Author

@wangfpp it is not a bug report, it is a feature request.
And I was writing my workaround at the end of the post.
Of course you can surely monkey patch the error object somehow, but the goal would be to have the error code in the official axios package

@jiangxiaoxin
Copy link

Maybe it's just a feature

H%)MG47NV6MV20Q%0Z1Z3_T

@aetonsi
Copy link

aetonsi commented May 28, 2020

Hi,
i'd like to add that having different Error constructors (one for each type of error, including a generic one for all of the "low level network errors" xhr.js#L80 ) would be a very clean and simple solution.

It would allow a better error detection for us users (solving or helping to solve issues like #383 , #1296 , #838 , #204 , #2103 ) and libraries (for example axios-retry, as it does here index.js#L9 ).

Have a nice day

@viridia
Copy link

viridia commented Jul 31, 2020

I'm also running into this issue. In my case, I want to be able to produce a localized version of the error message, with additional context for the user to understand what happened. Simply comparing the error message for equality with the string 'Network error' seems dodgy. It would also be great if axios could provide any additional information about the underlying error condition.

@jasonsaayman
Copy link
Member

See #4209

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
v1.0.0
  
To do
Development

No branches or pull requests

7 participants