I am trying to have a request and response interceptor setup for Axios when I make Post requests, however I can only get the request interceptor to respond, and nothing else, I've included an example of it not running:
Here is the axios setup:
import axios from "axios";
axios.defaults.baseURL = "https://btk7dl15c9.api.quickmocker.com";
axios.interceptors.request.use(
async (config) => {
console.log("request ok");
return config;
},
(error) => {
console.log("request error");
return Promise.reject(error);
}
);
axios.interceptors.response.use(
(response) => {
console.log("response ok");
return response;
},
(error) => {
console.log("response error");
return Promise.reject(error);
}
);
export default {
methods: {
axiosPost(url, data) {
return axios.post(url, data);
}
}
};
https://codesandbox.io/s/keen-shockley-xccsx
I need to be able to intercept 401 to be able to make a token refresh call (not included with the example)
CodePudding user response:
You used "axios": "0.21.2"
which it seems to have a bug in the interceptor that they fixed in v0.21.3
if you up to 0.21.3
or down to 0.21.1
this should fix your issue.
checkout the release log : https://github.com/axios/axios/releases/tag/0.21.3