最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - axios interceptor's error function is called multiple times - Stack Overflow

programmeradmin1浏览0评论

I am using axios interceptors to log all the api errors to a backend server at one mon place. The problem is, if one api call fails the logError function is called multiple times and multiple duplicate requests were sent for logging.

Here's my code

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

I am using axios interceptors to log all the api errors to a backend server at one mon place. The problem is, if one api call fails the logError function is called multiple times and multiple duplicate requests were sent for logging.

Here's my code

axios.interceptors.response.use(response => {
    return response;
},
error => {
    logError(error.message);
    return Promise.reject(error);
})
Share Improve this question asked Aug 6, 2020 at 6:52 Sathish Kumar SekarSathish Kumar Sekar 111 silver badge4 bronze badges 2
  • 1 Where is your interceptor added? If it's inside a function that is always called (or multiple times called), that should be the problem. Please provide more code regarding this interceptor that you're using. – Mihai Moraru Commented Aug 6, 2020 at 7:52
  • Interceptor code is added in app.js file which will be rendered only once. Also, this is happening only when the backend api is throwing error. I see multiple interceptor calls happening at a time. – Sathish Kumar Sekar Commented Aug 6, 2020 at 8:46
Add a ment  | 

1 Answer 1

Reset to default 8

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.

发布评论

评论列表(0)

  1. 暂无评论