diff options
| author | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-03-26 00:37:41 +0000 |
|---|---|---|
| committer | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-03-26 00:37:41 +0000 |
| commit | e0dfb55c5457aec489fc084c4567e791b4c65eb1 (patch) | |
| tree | 68543a65d88f5afb3a0202925804103daa91bc6f /lib/handle-error.ts | |
3/25 까지의 대표님 작업사항
Diffstat (limited to 'lib/handle-error.ts')
| -rw-r--r-- | lib/handle-error.ts | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/handle-error.ts b/lib/handle-error.ts new file mode 100644 index 00000000..1f608723 --- /dev/null +++ b/lib/handle-error.ts @@ -0,0 +1,22 @@ +import { toast } from "sonner" +import { z } from "zod" + +export function getErrorMessage(err: unknown) { + const unknownError = "Something went wrong, please try again later." + + if (err instanceof z.ZodError) { + const errors = err.issues.map((issue) => { + return issue.message + }) + return errors.join("\n") + } else if (err instanceof Error) { + return err.message + } else { + return unknownError + } +} + +export function showErrorToast(err: unknown) { + const errorMessage = getErrorMessage(err) + return toast.error(errorMessage) +} |
