-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #279 from MovieReviewComment/feature/issue-268/sep…
…erate-utils [#268] Seperate validateAndGetData and handleApiError to re-use
- Loading branch information
Showing
4 changed files
with
78 additions
and
49 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
'use client'; | ||
|
||
import { useToast } from '@/context/common/toast-context'; | ||
import { isErrorWithMessage } from '@/lib/utils/common/error'; | ||
|
||
export function useApiError() { | ||
const { emitToast } = useToast(); | ||
|
||
const handleApiError = (error: unknown) => { | ||
if (isErrorWithMessage(error)) { | ||
emitToast(error.message, 'error'); | ||
} else { | ||
// TODO: throw new Error and move to global error handler | ||
console.error(error); | ||
emitToast('알 수 없는 에러가 발생했습니다. 다시 시도해주세요.', 'error'); | ||
} | ||
}; | ||
|
||
return { handleApiError }; | ||
} |
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