We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 645cf79 commit 55f54bbCopy full SHA for 55f54bb
apps/site/util/fetch.ts
@@ -3,11 +3,12 @@ type RetryOptions = RequestInit & {
3
delay?: number;
4
};
5
6
-type FetchError = {
7
- cause: {
8
- code: string;
9
- };
10
-};
+const isTimeoutError = (e: unknown): boolean =>
+ e instanceof Error &&
+ typeof e.cause === 'object' &&
+ e.cause !== null &&
+ 'code' in e.cause &&
11
+ e.cause.code === 'ETIMEDOUT';
12
13
export const fetchWithRetry = async (
14
url: string,
@@ -22,7 +23,7 @@ export const fetchWithRetry = async (
22
23
e
24
);
25
- if (i === maxRetry || (e as FetchError).cause.code !== 'ETIMEDOUT') {
26
+ if (i === maxRetry || !isTimeoutError(e)) {
27
throw e;
28
}
29
0 commit comments