简体   繁体   中英

React Axios Handle 401

how to handle 401 Unauthorized status code with Axios Interceptor. This snippet print error in console but I still get RED error code in console, how to remove it?

axios.interceptors.response.use(
 response => {
   console.log("Axios Response: ", response);
   return response;
},
error => {
 if (error.response.status === 401) {
  console.log("RESPONSE 401");
  return Promise.reject(error.response);
}
console.log("Axios Response Error: ", error.response);
return Promise.reject(error);

} );

在此处输入图片说明

What you see is most probably automatic logging by Chrome and you can't remove it. When I open debugger on StackOverflow's page I see 2 such requests that were blocked by ad blocker:

被阻止的请求

You can maybe try removing both return Promise.reject(error.response); calls but I don't think this will help any.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM