0

We have react app and it implements axios interceptors, means if any network call responds 401 it redirect to login page. Next, we are using another react local library(lets say authLib) which is also implements same axios interceptors. So when network responds 401 error, both are executing(one for main app and another one for local library). How can we avoid to call once or override the axios interceptor.

var axiosObj = axios.create(); 
axiosObj.interceptors.request.use(function (config) {                               
return response;                                                                        
}, function (error) {                                                                  
if (error && error.response && error.response.status === 401) {
 logout();
return;  }                                                                         
return Promise.reject(error);});
Manas Kumar
  • 2,411
  • 3
  • 16
  • 23
  • can't you remove the redirect logic from axios-interceptor and let the other library do it – Charchit Kapoor Jul 12 '22 at 08:10
  • Avoid adding interceptors on the default `axios` instance. Instead, create new instances – Phil Jul 12 '22 at 08:23
  • Does this answer your question? [Axios interceptor intercepting all Axios requests](https://stackoverflow.com/questions/64672337/axios-interceptor-intercepting-all-axios-requests) – Phil Jul 12 '22 at 08:31

0 Answers0