Skip to content

Commit 55f54bb

Browse files
committed
Avoid unsafe access to e.cause.code
1 parent 645cf79 commit 55f54bb

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

apps/site/util/fetch.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ type RetryOptions = RequestInit & {
33
delay?: number;
44
};
55

6-
type FetchError = {
7-
cause: {
8-
code: string;
9-
};
10-
};
6+
const isTimeoutError = (e: unknown): boolean =>
7+
e instanceof Error &&
8+
typeof e.cause === 'object' &&
9+
e.cause !== null &&
10+
'code' in e.cause &&
11+
e.cause.code === 'ETIMEDOUT';
1112

1213
export const fetchWithRetry = async (
1314
url: string,
@@ -22,7 +23,7 @@ export const fetchWithRetry = async (
2223
e
2324
);
2425

25-
if (i === maxRetry || (e as FetchError).cause.code !== 'ETIMEDOUT') {
26+
if (i === maxRetry || !isTimeoutError(e)) {
2627
throw e;
2728
}
2829

0 commit comments

Comments
 (0)