-
-
Notifications
You must be signed in to change notification settings - Fork 11.6k
Error response interceptor receives JSON stringified payload on error.config.data #3986
Copy link
Copy link
Closed
Description
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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels