-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Refactor : 리렌더 방지 * New : 글로벌팝업 에러핸들링 적용 * Minor : tsx -> ts 확장자 변경 * New : 글로벌팝업 적용 * New : 토큰제거로직 추가
- Loading branch information
1 parent
006ae97
commit 65d3e68
Showing
13 changed files
with
61 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,24 @@ | ||
"use client"; | ||
// import { useGlobalSnackbarStore } from "@/store/useGlobalSnackbarStore"; | ||
import { useGlobalSnackbarStore } from "@/store/useGlobalSnackbarStore"; | ||
import { isAxiosError } from "axios"; | ||
import { useCallback } from "react"; | ||
|
||
export default function ErrorHandler(error: Error) { | ||
// const { fireToast } = useGlobalSnackbarStore(); | ||
if (isAxiosError(error) && error.response) { | ||
// FIXME : Zustand 사용 연구 | ||
// error.response.status === 401 && fireToast("로그인 후 이용 가능합니다"); | ||
error.response.status === 401 && console.log("로그인 후 이용 가능합니다"); | ||
} | ||
} | ||
/** | ||
* Axios 에러의 status 코드를 판별해 적절한 토스트팝업을 표출해주는 함수를 리런하는 훅 | ||
* @returns errorHandler (error)=>void | ||
*/ | ||
export const useErrorHandler = () => { | ||
const fireToast = useGlobalSnackbarStore((state) => state.fireToast); | ||
|
||
const errorHandler = useCallback((error: Error) => { | ||
if (isAxiosError(error) && error.response) { | ||
switch (error.response.status) { | ||
case 401: | ||
fireToast("로그인 후 이용 가능합니다"); | ||
// 토큰이 만료된 경우가 대부분이므로 토큰제거 | ||
localStorage.removeItem('accessToken') | ||
} | ||
} | ||
}, []); | ||
return errorHandler; | ||
}; |