From 2e5ff53d7271509accc226e83d76d1785350b1d2 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 13 Jul 2018 12:42:01 +0200 Subject: -fetch'; --- packages/utils/src/fetchAsync.ts | 16 +++++++++------- packages/utils/src/index.ts | 1 - 2 files changed, 9 insertions(+), 8 deletions(-) (limited to 'packages/utils/src') 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 => { - 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'; -- cgit