1import { APISettings } from '../settings';
2import { FetchLike } from './client.types';
3
4const debug = require('debug')('expo:api:fetch:offline') as typeof console.log;
5
6/** Wrap fetch with support for APISettings offline mode. */
7export function wrapFetchWithOffline(fetchFunction: FetchLike): FetchLike {
8  // NOTE(EvanBacon): DO NOT RETURN AN ASYNC WRAPPER. THIS BREAKS LOADING INDICATORS.
9  return function fetchWithOffline(url, options = {}) {
10    if (APISettings.isOffline) {
11      debug('Skipping network request: ' + url);
12      options.timeout = 1;
13    }
14    return fetchFunction(url, options);
15  };
16}
17