Skip to content

Commit

Permalink
fix: clean apolloClient timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
munkhsaikhan committed Mar 7, 2024
1 parent 5b6a717 commit 458ff06
Showing 1 changed file with 0 additions and 30 deletions.
30 changes: 0 additions & 30 deletions packages/erxes-ui/src/apolloClient.ts
Expand Up @@ -16,40 +16,10 @@ import addMergeKeyfieldPolicy from './add-merge-keyfield-policy';

const { REACT_APP_API_SUBSCRIPTION_URL, REACT_APP_API_URL } = getEnv();

async function fetchWithTimeout(
input: RequestInfo | URL,
init?: RequestInit | undefined,
) {
const timeout = init?.headers?.['x-timeout'] || 30_000;
const controller = new AbortController();
const id = setTimeout(() => controller.abort('Request timed out'), timeout);

try {
const response = await fetch(input, {
...init,
signal: controller.signal,
});
return response;
} catch (e) {
if (controller.signal.aborted) {
console.error(
`Request timed out. Client side timeout limit ${timeout}ms exceeded.`,
init,
);
throw new Error(controller.signal.reason || 'Request timed out');
} else {
throw e;
}
} finally {
clearTimeout(id);
}
}

// Create an http link:
const httpLink = createHttpLink({
uri: `${REACT_APP_API_URL}/graphql`,
credentials: 'include',
fetch: fetchWithTimeout,
});

// Error handler
Expand Down

0 comments on commit 458ff06

Please sign in to comment.