Skip to content
Closed
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,18 @@ export async function multicall(
}
}

export function fetchWithTimeout(url, options): Promise<any> {
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',
Expand Down Expand Up @@ -470,6 +480,7 @@ export function getNumberWithOrdinal(n) {
export default {
call,
multicall,
fetchWithTimeout,
subgraphRequest,
ipfsGet,
getUrl,
Expand Down