Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix login failed toast vague message #176

Merged
merged 3 commits into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion frontend/app/auth/auth-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
37 changes: 31 additions & 6 deletions frontend/components/auth/login-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
});
}
}
};

Expand Down