1// Add a request interceptor
2axios.interceptors.request.use(function (config) {
3 // Do something before request is sent
4 return config;
5 }, function (error) {
6 // Do something with request error
7 return Promise.reject(error);
8 });
9
10// Add a response interceptor
11axios.interceptors.response.use(function (response) {
12 // Any status code that lie within the range of 2xx cause this function to trigger
13 // Do something with response data
14 return response;
15 }, function (error) {
16 // Any status codes that falls outside the range of 2xx cause this function to trigger
17 // Do something with response error
18 return Promise.reject(error);
19 });
1// Add a request interceptor
2axios.interceptors.request.use(function (config) {
3 // Do something before request is sent
4 return config;
5 }, function (error) {
6 // Do something with request error
7 return Promise.reject(error);
8 });
9
10// Add a response interceptor
11axios.interceptors.response.use(function (response) {
12 // Any status code that lie within the range of 2xx cause this function to trigger
13 // Do something with response data
14 return response;
15 }, function (error) {
16 // Any status codes that falls outside the range of 2xx cause this function to trigger
17 // Do something with response error
18 return Promise.reject(error);
19 });
20