Skip to content

Commit

Permalink
fix: Missing handling for an unknown error type
Browse files Browse the repository at this point in the history
  • Loading branch information
amattu2 committed Sep 9, 2024
1 parent 765f95a commit 62a503e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/components/Header/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,18 @@ describe("Implementation Requirements", () => {
});
});
});

it("should show an error snackbar when there is an unknown error type", async () => {
render(<Header />, {
wrapper: (p) => (
<Parent error={["Some unknown representation of an error"] as unknown as string} {...p} />
),
});

await waitFor(() => {
expect(global.mockEnqueue).toHaveBeenCalledWith("An unknown error occurred during login", {
variant: "error",
});
});
});
});
9 changes: 7 additions & 2 deletions src/components/Header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,16 @@ const Header = () => {
const tabletAndMobile = useMediaQuery("(max-width: 1024px)");

useEffect(() => {
if (typeof authError !== "string") {
if (!authError) {
return;
}

enqueueSnackbar(authError, { variant: "error" });
enqueueSnackbar(
typeof authError === "string" && authError?.length > 0
? authError
: "An unknown error occurred during login",
{ variant: "error" }
);
}, [authError]);

return (
Expand Down

0 comments on commit 62a503e

Please sign in to comment.