Skip to content

Commit

Permalink
Add error handling for non-Error instances in fetchUser function
Browse files Browse the repository at this point in the history
* Check if `error` is an instance of `Error` before accessing `message` property
* Set a generic error message if `error` is not an instance of `Error`
  • Loading branch information
NateIsern committed Nov 15, 2024
1 parent 271ab6f commit dfa51ac
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/components/auth/AccountSwitcherModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ export const AccountSwitcherModal = forwardRef<
const fetchedUser = await getUserById(session?.user?.id);
setUser(fetchedUser);
} catch (error) {
setError(error.message);
if (error instanceof Error) {
setError(error.message);
} else {
setError("An unknown error occurred");
}
}
};

Expand Down

0 comments on commit dfa51ac

Please sign in to comment.