1import { FetchLike } from './client.types'; 2import { env } from '../../utils/env'; 3 4const debug = require('debug')('expo:api:fetch:offline') as typeof console.log; 5 6/** Wrap fetch with support for `EXPO_OFFLINE` to disable network requests. */ 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 (env.EXPO_OFFLINE) { 11 debug('Skipping network request: ' + url); 12 options.timeout = 1; 13 } 14 return fetchFunction(url, options); 15 }; 16} 17