Skip to content

Commit

Permalink
Update error handler to handle custom error response
Browse files Browse the repository at this point in the history
  • Loading branch information
wet6123 committed Aug 3, 2024
1 parent 1e42017 commit 1e2907a
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions frontend/src/hooks/useErrorHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { useCallback } from "react";
interface CustomError extends Error {
response?: {
data: {
error?: string;
message: string;
error: string;
message?: string;
statusCode: number;
};
};
Expand All @@ -15,8 +15,9 @@ export function useErrorHandler() {
const { enqueueSnackbar } = useSnackbar();
const handleError = useCallback(
(error: CustomError) => {
console.error(error);
enqueueSnackbar(
error.response?.data.error || error.message || "Something went wrong...",
error.response?.data.message || error.message || "Something went wrong...",
{ variant: "error" }
);
},
Expand Down

0 comments on commit 1e2907a

Please sign in to comment.