summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/lib/utils/suppress_ajax_errors_during_navigation.js
blob: fb4d9b7de9cb90f40bd43c19ba59baa1fe90a893 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/**
 * An Axios error interceptor that suppresses AJAX errors caused
 * by the request being cancelled when the user navigates to a new page
 */
export default (err, isUserNavigating) => {
  if (isUserNavigating && err.code === 'ECONNABORTED') {
    // If the user is navigating away from the current page,
    // prevent .then() and .catch() handlers from being
    // called by returning a Promise that never resolves
    return new Promise(() => {});
  }

  // The error is not related to browser navigation,
  // so propagate the error
  return Promise.reject(err);
};