From 37a452713c6cd77aaa9bacd27e7ddf89a1aa90ce Mon Sep 17 00:00:00 2001 From: ChaituVR Date: Fri, 16 Jun 2023 17:10:27 +0530 Subject: [PATCH 1/3] Fetch with timeout --- src/utils.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/utils.ts b/src/utils.ts index 750f16389..c25d86396 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -133,8 +133,18 @@ export async function multicall( } } +export function fetchWithTimeout(url, options): Promise { + const timeout = 30000 || options.timeout; + return Promise.race([ + fetch(url, options), + new Promise((_, reject) => + setTimeout(() => reject(new Error('Request timeout')), timeout) + ) + ]); +} + export async function subgraphRequest(url: string, query, options: any = {}) { - const res = await fetch(url, { + const res = await fetchWithTimeout(url, { method: 'POST', headers: { Accept: 'application/json', @@ -461,6 +471,7 @@ export function getNumberWithOrdinal(n) { export default { call, multicall, + fetchWithTimeout, subgraphRequest, ipfsGet, getUrl, From 53139e8f9fb94b7db425d130ade231e6d3324680 Mon Sep 17 00:00:00 2001 From: Chaitanya Date: Fri, 25 Aug 2023 21:04:24 +0530 Subject: [PATCH 2/3] Update src/utils.ts --- src/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils.ts b/src/utils.ts index 3edc5c2b6..9d68d78be 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -136,7 +136,7 @@ export async function multicall( } export function fetchWithTimeout(url, options): Promise { - const timeout = 30000 || options.timeout; + const timeout = options.timeout || 30000; return Promise.race([ fetch(url, options), new Promise((_, reject) => From 9fb3f60f82a228e47e00c9178288610a2623a0ed Mon Sep 17 00:00:00 2001 From: Chaitanya Date: Fri, 25 Aug 2023 21:06:38 +0530 Subject: [PATCH 3/3] v0.5.7 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 160a1325c..02a6a3d82 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@snapshot-labs/snapshot.js", - "version": "0.5.6", + "version": "0.5.7", "repository": "snapshot-labs/snapshot.js", "license": "MIT", "main": "dist/snapshot.cjs.js",