I have made axios post request but my server couldn't handle the request so it returns some error. In such cases, I need to make the request again in my axios response interceptor. Any easy way to do
            Asked
            
        
        
            Active
            
        
            Viewed 1,850 times
        
    1 Answers
2
            
            
        You can try this:
axios.interceptors.response.use(undefined, (err) => {
  const count = (err.config || {}).retryCount;
  if (count > 0) { 
    return axios({ ...err.config, retryCount: count - 1 });
  }
  throw err;
});
axios.get('/', { retryCount: 3 });
Add in && err.status === ... if you only want to retry for certain errors (probably only server errors rather than client errors).
 
    
    
        Roy Wang
        
- 11,112
- 2
- 21
- 42
