Intercept 401 response code with axios

Here is how we can globally intercept all requests that result with the 401 (unauthorized) error code.

With this response, a SPA application might redirect the user to a login page:


axios.interceptors.response.use(response => {
         return response;
      }, error => {
      if (error.response.status === 401) {

      }

      return Promise.reject(error);
});

Post a Comment

Previous Post Next Post