Skip to content

Commit a577dd4

Browse files
committed
fix(login): improve error handling for authentication and server errors
1 parent d4fea1d commit a577dd4

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.3.2
1+
1.3.3

frontend/routes/login.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,17 @@ export const handler: Handlers<Data> = {
3030
// Validate credentials by hitting a protected GET
3131
try {
3232
await backendGet("/api/v1/invoices", basic);
33-
} catch (_e) {
34-
return ctx.render({ error: "Invalid credentials", username });
33+
} catch (e) {
34+
const errorMessage = e instanceof Error ? e.message : String(e);
35+
// Check if it's an authentication error (401/403) vs other errors
36+
if (errorMessage.includes("401") || errorMessage.includes("403")) {
37+
return ctx.render({ error: "Invalid credentials", username });
38+
} else if (errorMessage.includes("500") || errorMessage.includes("502") || errorMessage.includes("503") || errorMessage.includes("504")) {
39+
return ctx.render({ error: "Server error. Please try again later.", username });
40+
} else {
41+
// Network errors, timeouts, or other connection issues
42+
return ctx.render({ error: "Unable to connect to server. Please check your connection and try again.", username });
43+
}
3544
}
3645
const headers = new Headers({
3746
...setAuthCookieHeaders(basic),

0 commit comments

Comments
 (0)