How to use fetch-intercept - 5 common examples

To help you get started, we’ve selected a few fetch-intercept examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github niunai2016 / ReactNativeAppDemo / src / services / base-service.js View on Github external
/**
 * 基础服务类封装
 * BaseService
 */
import fetchIntercept from 'fetch-intercept'
import constants from '../common/constants';
import ServiceError from '../common/service-error';
import code from '../common/code';

const fetchApi = fetch; // eslint-disable-line

fetchIntercept.register({
  request: function (url, config) {
    return [url, config];
  },
  requestError: function (error) {
    return Promise.reject(error);
  },
  response: function (res) {
    return res;
  },
  responseError: function (error) {
    return Promise.reject(error);
  }
});

export default class BaseService {
  constructor(props){
github Xabaril / Esquio / src / Esquio.UI / ClientApp / src / app / core / interceptor.ts View on Github external
export function registerInterceptor(next = null) {
  nprogress.configure({ showSpinner: false });
  const authService = container.get(cid.IAuthService);

  fetchIntercept.register({
    request: function (url, config) {
      nprogress.start();

      config = config || {};
      const headers = config.headers || {};

      config.headers = {
        ...headers,
        'Content-Type': 'application/json',
        'x-api-version': '2.0',
        Authorization: `Bearer ${authService.user.access_token}`
      };
      return [url, config];
    },

    requestError: function (error) {
github CKGrafico / Frontend-Boilerplates / client / middleware / interceptors.ts View on Github external
}

      return _fetch.call(this, ...[localUrl, ...args]);
    };

    fetch.prototype = Object.create(_fetch.prototype);
    fetch.prototype.constructor = fetch;

    global['fetch'] = fetch;
  } else {
    require('whatwg-fetch');
  }

  const fetchIntercept = require('fetch-intercept');

  fetchIntercept.register({
    request: function (url, defaultConfig) {
      if (!url.includes || !url.includes(store.state.config.settings.apiUrl)) {
        return [url, defaultConfig];
      }

      const config = defaultConfig || {};
      config.headers = config.headers || {};

      config.headers['Accept-Language'] = app.i18n.locale || 'en';

      return [url, config];
    },

    requestError: (error) => {
      return Promise.reject(error);
    },
github mikerourke / toggl-to-clockify-web / src / utils / httpInterceptor.ts View on Github external
export function initInterceptor(store: Store): VoidFunction {
  return fetchIntercept.register({
    request(url, config: RequestConfig = {}) {
      const { toolName, context, endpoint } = extrapolateFromUrl(url);

      const { credentials } = store.getState();

      if (config.body) {
        config.body = JSON.stringify(config.body);
      }

      const baseHeaders = getHeaders(toolName, credentials);
      if (config.headers) {
        config.headers = {
          ...config.headers,
          ...baseHeaders,
        };
      } else {

fetch-intercept

Interceptor library for the native fetch command inspired by angular http intercepts.

MIT
Latest version published 3 years ago

Package Health Score

50 / 100
Full package analysis

Popular fetch-intercept functions