Skip to content

Commit ec17407

Browse files
committed
fix(fetch): stricter error check in authedFetch
1 parent 7cc7186 commit ec17407

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/lib/fetch.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { getDefaultStore } from "jotai";
22
import { accessTokenAtom } from "@/atoms/authTokens";
33
import { SignalError } from "@/lib/error";
4-
import { SignalResponse } from "@/types/common";
4+
import { ErrorResponse, SignalResponse } from "@/types/common";
55

66
const store = getDefaultStore();
77

@@ -32,8 +32,13 @@ export const authedFetch = async <T>(
3232

3333
const res = (await response.json()) as SignalResponse<T>;
3434

35-
if (!("result" in res)) {
36-
throw new SignalError(res.message, res.status, res.timestamp);
35+
if (!("result" in res) || response.status >= 400) {
36+
const errorRes = res as ErrorResponse;
37+
throw new SignalError(
38+
errorRes.message ?? "알 수 없는 오류",
39+
errorRes.status ?? response.status,
40+
errorRes.timestamp ?? new Date().toISOString(),
41+
);
3742
}
3843

3944
return res.result;

0 commit comments

Comments
 (0)