简体   繁体   English

axios 拦截器的错误 function 被多次调用

[英]axios interceptor's error function is called multiple times

I am using axios interceptors to log all the api errors to a backend server at one common place.我正在使用 axios 拦截器将所有 api 错误记录到一个常见位置的后端服务器。 The problem is, if one api call fails the logError function is called multiple times and multiple duplicate requests were sent for logging.问题是,如果一个 api 调用失败,则会多次调用 logError function 并发送多个重复请求以进行日志记录。

Here's my code这是我的代码

axios.interceptors.response.use(response => {
    return response;
},
error => {
    logError(error.message);
    return Promise.reject(error);
})

This might be issue that your interceptor code initialized multiple times, I was facing the same issue and when it initialized once, solved the issue.这可能是您的拦截器代码多次初始化的问题,我遇到了同样的问题,当它初始化一次时,解决了这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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