Skip to content

Error response interceptor receives JSON stringified payload on error.config.data #3986

@rdsedmundo

Description

@rdsedmundo

This is the same report as #1386, it shouldn't have been closed because only a workaround was provided and this needs at least a documentation update because it's highly unexpected.

Describe the bug

While writing a request interceptor and accessing config.data you receive a JSON object, but if you access the error.config.data it's a string (JSON stringified of the original object). This is misleading if you want to retry the request (i.e axios.request(error.config)) and the request interceptor is expecting an object.

To Reproduce

axios.interceptors.request.use(config => {
  assert(typeof config.data === 'object');
  
  return config;
});

axios.interceptors.response.use(() => (),
  (error) => {
    // this fails, error.config.data is a string
    assert(typeof error.config.data === 'object');
  });
  
axios.post('https://non-existent-url-03203o1023o103o/data', {hello: 'world'});

Expected behavior

The object should be preserved for consistency as both parameters are called "config", or at least the documentation should point out this difference.

Environment

  • Axios Version 0.21.1
  • Node.js Version 14.17.0

Additional context/Screenshots

N/A

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