diff options
Diffstat (limited to 'packages/utils/src')
-rw-r--r-- | packages/utils/src/fetchAsync.ts | 16 | ||||
-rw-r--r-- | packages/utils/src/index.ts | 1 |
2 files changed, 9 insertions, 8 deletions
diff --git a/packages/utils/src/fetchAsync.ts b/packages/utils/src/fetchAsync.ts index 7cb2c1759..a009f0c86 100644 --- a/packages/utils/src/fetchAsync.ts +++ b/packages/utils/src/fetchAsync.ts @@ -1,29 +1,31 @@ -import { FetchRequest } from '@0xproject/types'; import 'isomorphic-fetch'; export const fetchAsync = async ( endpoint: string, - options: FetchRequest, + options: RequestInit = {}, timeoutMs: number = 20000, ): Promise<Response> => { - let finalOptions; + let optionsWithAbortParam; if ((process as any).browser === true) { const controller = new AbortController(); const signal = controller.signal; setTimeout(() => { controller.abort(); }, timeoutMs); - finalOptions = { + optionsWithAbortParam = { signal, ...options, }; } else { - finalOptions = { + // HACK: the `timeout` param only exists in `node-fetch`, and not on the `isomorphic-fetch` + // `RequestInit` type. Since `isomorphic-fetch` conditionally wraps `node-fetch` when the + // execution environment is `Node.js`, we need to cast it to `any` in that scenario. + optionsWithAbortParam = { timeout: timeoutMs, ...options, - }; + } as any; } - const response = await fetch(endpoint, finalOptions); + const response = await fetch(endpoint, optionsWithAbortParam); return response; }; diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts index 48fd6152e..b8e0b1775 100644 --- a/packages/utils/src/index.ts +++ b/packages/utils/src/index.ts @@ -9,4 +9,3 @@ export { abiUtils } from './abi_utils'; export { NULL_BYTES } from './constants'; export { errorUtils } from './error_utils'; export { fetchAsync } from './fetchAsync'; -export { FetchRequest } from '@0xproject/types'; |