diff --git a/frontend/app/auth/auth-context.tsx b/frontend/app/auth/auth-context.tsx index cdbd127d59..ca8a9e0be4 100644 --- a/frontend/app/auth/auth-context.tsx +++ b/frontend/app/auth/auth-context.tsx @@ -75,7 +75,16 @@ const AuthProvider: React.FC<{ children: ReactNode }> = ({ children }) => { ); if (!response.ok) { - throw new Error("Not OK"); + switch (response.status) { + case 400: + throw new Error("Email and/or password is missing."); + case 401: + throw new Error("Invalid email or password."); + case 500: + throw new Error("Internal server error. Please try again later."); + default: + throw new Error("Unexpected error occurred."); + } } const resJson = await response.json(); diff --git a/frontend/components/auth/login-form.tsx b/frontend/components/auth/login-form.tsx index 7f415c5427..a8590a195b 100644 --- a/frontend/components/auth/login-form.tsx +++ b/frontend/components/auth/login-form.tsx @@ -41,12 +41,37 @@ export function LoginForm() { description: "Login Failed.", }); } - } catch (err) { - toast({ - title: "Error", - variant: "destructive", - description: "Login Failed.", - }); + } catch (err: unknown) { + if (err instanceof Error) { + let description_text = ""; + switch (err.message) { + case "Email and/or password is missing.": + description_text = "Please provide both email and password."; + break; + case "Invalid email or password.": + description_text = "Username or password is incorrect."; + break; + case "Internal server error. Please try again later.": + description_text = + "There was an issue with the server. Please try again later."; + break; + default: + description_text = + "An unexpected error occurred. Please try again."; + break; + } + toast({ + title: "Error", + variant: "destructive", + description: description_text, + }); + } else { + toast({ + title: "Error", + variant: "destructive", + description: "An unexpected error occurred. Please try again.", + }); + } } };