Welcome to mirror list, hosted at ThFree Co, Russian Federation.

suppress_network_errors_during_navigation_link.js « apollo « lib « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ad92bd4de42490a51d3026f82c89c65a83654c34 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { Observable } from 'apollo-link';
import { onError } from 'apollo-link-error';
import { isNavigatingAway } from '~/lib/utils/is_navigating_away';

/**
 * Returns an ApolloLink (or null if not enabled) which supresses network
 * errors when the browser is navigating away.
 *
 * @returns {ApolloLink|null}
 */
export const getSuppressNetworkErrorsDuringNavigationLink = () => {
  if (!gon.features?.suppressApolloErrorsDuringNavigation) {
    return null;
  }

  return onError(({ networkError }) => {
    if (networkError && isNavigatingAway()) {
      // Return an observable that will never notify any subscribers with any
      // values, errors, or completions. This ensures that requests aborted due
      // to navigating away do not trigger any failure behaviour.
      //
      // See '../utils/suppress_ajax_errors_during_navigation.js' for an axios
      // interceptor that performs a similar role.
      return new Observable(() => {});
    }

    // We aren't suppressing anything here, so simply do nothing.
    // The onError helper will forward all values/errors/completions from the
    // underlying request observable to the next link if you return a falsey
    // value.
    //
    // Note that this return statement is technically redundant, but is kept
    // for explicitness.
    return undefined;
  });
};