axios: Broken interceptor error response

Hello, I have upgraded axios from 0.12 to 0.16.2 and it looks like that interceptors response is quite diffrent:

Interceptor example code:

axios.interceptors.response.use(response => Promise.resolve(response), (error) => {
  console.log(error);
  return Promise.reject(error);
});

On version 0.12 it returns nice object:

screenshot 2017-09-14 14 01 29

However on version 0.16.2 it seems to return error stack for the request:

screenshot 2017-09-14 13 59 00

Making interceptors in axios quite useless in my project (I am using it to refresh access token for logged user).

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 4
  • Comments: 15

Most upvoted comments

Using v0.17.1

Also the same here, error.response is undefined.

Object.keys(error).forEach(key => console.log(key)) returns config, request, response

but error.response returns undefined. So it’s there but undefined.

Seems to be broken for me as well. Only keys are config and request. Can’t get the status code.

0.18 error.response returns undefined. error.status returns undefined.

I use the 0.17.1 log only having the config and request but the same version in my workmate’s project having the response ! so sad!

Try error.data or error.status to get all data listed above.

It means the error rejected by promise is an error object not a plain object.

You can traversal this error object by using Object.keys(error).forEach(key => ...)