Skip to content

Commit 579acc6

Browse files
committed
refactor: 코드리뷰 반영
1 parent 32a047f commit 579acc6

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

app/(main)/setting/page.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
"use client";
2+
import { HTTPError } from "ky";
3+
import { HTTP_STATUS_CODE } from "@/shared/constants/api";
24
import { useLogout } from "@/app/(auth)/_api/auth.queries";
35
import { userQueryOptions } from "@/shared/api/queries/user";
46
import PopupReport from "@/shared/ui/popup/popup-report";
@@ -18,8 +20,10 @@ const Setting = () => {
1820
const router = useRouter();
1921
const queryClient = useQueryClient();
2022
const { data: userInfo } = useQuery(userQueryOptions.userInfo({
21-
onError: (_error) => {
22-
router.replace(PATH.LOGIN);
23+
onError: (error) => {
24+
if (error instanceof HTTPError && error.response.status === HTTP_STATUS_CODE.UNAUTHORIZED) {
25+
router.replace(PATH.LOGIN);
26+
}
2327
},
2428
}));
2529
const { open } = useOverlay();

shared/api/api-client.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,10 @@ const http = ky.create({
2222
async (error) => {
2323
if (error instanceof HTTPError) {
2424
const { response } = error;
25-
const url = error.request.url;
26-
27-
if (url.includes(ENDPOINTS.USER_INFO)) {
25+
const pathname = new URL(error.request.url).pathname;
26+
if (pathname.endsWith(ENDPOINTS.USER_INFO)) {
2827
return error;
2928
}
30-
3129
switch (response.status) {
3230
case HTTP_STATUS_CODE.UNAUTHORIZED: {
3331
window.location.replace(PATH.LOGIN);

shared/api/queries/user.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ export const userQueryOptions = {
1818
queryFn: () => {
1919
return apiClient.get<UserInfo>(ENDPOINTS.USER_INFO);
2020
},
21-
onError: options?.onError,
2221
...options,
2322
}),
2423
};

0 commit comments

Comments
 (0)