18d307f52SEvan Baconimport { FetchLike } from './client.types';
2*8a424bebSJames Ideimport { env } from '../../utils/env';
38d307f52SEvan Bacon
4474a7a4bSEvan Baconconst debug = require('debug')('expo:api:fetch:offline') as typeof console.log;
5474a7a4bSEvan Bacon
6e32ccf9fSEvan Bacon/** Wrap fetch with support for `EXPO_OFFLINE` to disable network requests. */
78d307f52SEvan Baconexport function wrapFetchWithOffline(fetchFunction: FetchLike): FetchLike {
882f3de79SEvan Bacon  // NOTE(EvanBacon): DO NOT RETURN AN ASYNC WRAPPER. THIS BREAKS LOADING INDICATORS.
982f3de79SEvan Bacon  return function fetchWithOffline(url, options = {}) {
10e32ccf9fSEvan Bacon    if (env.EXPO_OFFLINE) {
11474a7a4bSEvan Bacon      debug('Skipping network request: ' + url);
128d307f52SEvan Bacon      options.timeout = 1;
138d307f52SEvan Bacon    }
148d307f52SEvan Bacon    return fetchFunction(url, options);
158d307f52SEvan Bacon  };
168d307f52SEvan Bacon}
17