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

Status code is missing in toJSON method of axios error #2947

Closed
tsachis opened this issue May 5, 2020 · 1 comment
Closed

Status code is missing in toJSON method of axios error #2947

tsachis opened this issue May 5, 2020 · 1 comment

Comments

@tsachis
Copy link

tsachis commented May 5, 2020

Description
When calling the toJSON method on an axios error (inside a catch clause), the returned object does not include the error status code.
toJSON is useful for extracting the main error details, and the status code should be part of it as well.

To Reproduce
Run the below code. No status code field in the output.
The only place status code appears in the toJSON object is in the message: "Request failed with status code 404"

There's a status field (which is always undefined btw), but according to the code, it is a connection error string (for example, 'ECONNABORTED'), not the response numeric status code.

const axios = require('axios');

axios.get('http://google.com/404')
  .catch(function (error) {
    console.log(error.toJSON());
  })

Expected behavior
A numeric statusCode field should be part of the toJSON returned object.

Environment:

  • Axios Version 0.19.2
  • OS: OSX 10.14.6
  • Node v12.16.1
byrne-greg pushed a commit to byrne-greg/axios that referenced this issue May 8, 2020
byrne-greg added a commit to byrne-greg/axios that referenced this issue May 8, 2020
@jasonsaayman jasonsaayman added this to To do in v0.20.0 via automation May 12, 2020
@jasonsaayman jasonsaayman added this to the v0.20.0 milestone May 12, 2020
@jasonsaayman jasonsaayman removed this from To do in v0.20.0 Aug 25, 2020
@jasonsaayman jasonsaayman removed this from the v0.20.0 milestone Aug 25, 2020
jasonsaayman added a commit that referenced this issue Sep 5, 2021
* Adding HTTP status code to error.toJSON (#2947)

* Adding Error display div to internal server client.html

Co-authored-by: Jay <jasonsaayman@gmail.com>
@jasonsaayman
Copy link
Member

Fixed with #2956 2956

mbargiel pushed a commit to mbargiel/axios that referenced this issue Jan 27, 2022
* Adding HTTP status code to error.toJSON (axios#2947)

* Adding Error display div to internal server client.html

Co-authored-by: Jay <jasonsaayman@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants