diff --git a/packages/core/src/hooks/useAuth.ts b/packages/core/src/hooks/useAuth.ts index f07c5ba1..1fde9e61 100644 --- a/packages/core/src/hooks/useAuth.ts +++ b/packages/core/src/hooks/useAuth.ts @@ -47,7 +47,8 @@ export const useAuth = () => { * API 호출 후 catch에서 받아온 Error 객체를 인자로 넣어주세요 */ const handleTokenError = async (error: Error) => { - if (error.message === "403") { + const TOKEN_ERROR_STATUS = "403"; + if (error.message === TOKEN_ERROR_STATUS) { await reLogin(); location.reload(); } else { diff --git a/packages/service/src/pages/PartsCollection/PartsCollection.tsx b/packages/service/src/pages/PartsCollection/PartsCollection.tsx index 180db6a6..f339cb57 100644 --- a/packages/service/src/pages/PartsCollection/PartsCollection.tsx +++ b/packages/service/src/pages/PartsCollection/PartsCollection.tsx @@ -10,20 +10,12 @@ import { IMyParts } from "@watermelon-clap/core/src/types"; import { getAccessToken } from "@watermelon-clap/core/src/utils"; export const PartsCollection = () => { - const { getIsLogin, login, reLogin } = useAuth(); + const { getIsLogin, login, handleTokenError } = useAuth(); const [equippedPartsImg, setEquippedPartsImg] = useState(); - const getPartsData = async () => { - try { - return await apiGetMyParts(); - } catch (error: any) { - if (error.message === "403") { - reLogin().then(() => refetch()); - } - throw error; - } - }; + const getPartsData = () => + apiGetMyParts().catch(handleTokenError) as Promise; const { data: partsDatas, refetch } = useQuery({ queryKey: ["myParts", getAccessToken()],