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  return async function fetchWithOffline(url, options = {}) {
9    if (APISettings.isOffline) {
10      debug('Skipping network request: ' + url);
11      options.timeout = 1;
12    }
13    return fetchFunction(url, options);
14  };
15}
16