Skip to content

AxiosError ERR_NETWORK contains request as response #4655

@mengelbrecht

Description

@mengelbrecht

Describe the bug

When performing an axios request which is rejected with ERR_NETWORK the created AxiosError contains the request as response.
This leads to the issue that the response of the AxiosError contains the status code 200 and the body of the request although in reality no response was received.

I think the issue is that the request is passed as 5th parameter (response) of the AxiosError constructor here:

reject(new AxiosError('Network Error', AxiosError.ERR_NETWORK, config, request, request));

To Reproduce

Sample project:
sample.zip

Running the sample project with npm run test prints the following to the console:

error code: ERR_NETWORK
response status: 200
response body: {"foo":"bar"}

Expected behavior

The response field in the AxiosError created due to ERR_NETWORK should be undefined.

Environment

  • Axios Version 0.27.2
  • Adapter XHR
  • Browser -
  • Browser Version -
  • Node.js Version 18.0.0
  • OS: macOS 12.3.1
  • Additional Library Versions msw: ^0.39.2

Additional context/Screenshots

NA

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions