fix(login): show toast for non-401 errors on sgID profile#9768
Open
LoneRifle wants to merge 1 commit into
Open
fix(login): show toast for non-401 errors on sgID profile#9768LoneRifle wants to merge 1 commit into
LoneRifle wants to merge 1 commit into
Conversation
* fix(login): show error toast on sgID profile fetch non-401 errors * fix(login): show generic error message for unknown errors Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: LTA-Dong-Jun <Dong_Jun_CHEN_from.TP@lta.gov.sg> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Adds more explicit error-to-toast behavior for SGID profile selection failures by passing HTTP status through redirects and introducing a server-error i18n string.
Changes:
- Add
errors.serverErrorto common i18n types anden-sglocale. - Update SelectProfilePage to redirect to Login with a
?status=query param for non-401 errors. - Update LoginPage toast selection to show a server-error message for 5xx status codes.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| apps/frontend/src/i18n/locales/features/common/index.ts | Adds serverError string to the Common locale contract. |
| apps/frontend/src/i18n/locales/features/common/en-sg.ts | Provides the serverError English (SG) translation string. |
| apps/frontend/src/features/login/SelectProfilePage.tsx | Redirects to Login with status code context for non-401 failures. |
| apps/frontend/src/features/login/LoginPage.tsx | Maps 5xx status codes to a server-error toast, otherwise generic. |
Comments suppressed due to low confidence (1)
apps/frontend/src/features/login/LoginPage.tsx:1
- Two issues here: (1)
parseIntshould be called with an explicit radix to avoid inconsistent parsing (parseInt(statusCode ?? '', 10)). (2) The memoized callback depends ontas well asstatusCode; omittingtcan lead to stale translations if the language changes. Update the dependency list to includet(and any other referenced values not guaranteed stable).
import { useEffect, useMemo, useState } from 'react'
Comment on lines
132
to
+149
| // If redirected back here but already authed, redirect to dashboard. | ||
| if (user) window.location.replace(DASHBOARD_ROUTE) | ||
| // User doesn't have any profiles, should reattempt to login | ||
| if (profilesResponse.error) window.location.replace(LOGIN_ROUTE) | ||
|
|
||
| if (profilesResponse.error) { | ||
| const err = profilesResponse.error | ||
| const statusCode = err instanceof HttpError ? err.code : undefined | ||
|
|
||
| if (statusCode === StatusCodes.UNAUTHORIZED) { | ||
| // 401 — session invalid, redirect quietly | ||
| window.location.replace(LOGIN_ROUTE) | ||
| } else { | ||
| // all other HTTP errors — redirect with status so LoginPage can surface the appropriate toast. | ||
| // For non-HTTP errors (e.g. network failures), use a non-5xx sentinel so we fall back to the generic toast. | ||
| const statusParam = statusCode ?? 0 | ||
| window.location.replace(`${LOGIN_ROUTE}?status=${statusParam}`) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #9540
Merges #9543