fix(login): show error toast on sgID profile fetch non-401 errors#9543
Open
Strikerprv wants to merge 1 commit into
Open
fix(login): show error toast on sgID profile fetch non-401 errors#9543Strikerprv wants to merge 1 commit into
Strikerprv wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Improves the sgID login UX by ensuring sgID profile-fetch failures surface an error toast on the login page (instead of silently redirecting and potentially looping), and adds explicit messaging for 5xx server errors.
Changes:
- Update
SelectProfilePageto redirect to/login?status=<code>for non-401 sgID profile fetch errors. - Extend
LoginPage’s status-to-toast mapping to treat500–599as a dedicated “server error” message. - Add
errors.serverErrorto the common i18n typings anden-sglocale.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| apps/frontend/src/i18n/locales/features/common/index.ts | Adds serverError key to the Common i18n type. |
| apps/frontend/src/i18n/locales/features/common/en-sg.ts | Adds the serverError message string in en-sg. |
| apps/frontend/src/features/login/SelectProfilePage.tsx | Redirects sgID profile-fetch errors to login with an attached status code (except 401). |
| apps/frontend/src/features/login/LoginPage.tsx | Adds 5xx-range handling to show a dedicated server-error toast. |
Comment on lines
+136
to
+151
| if (profilesResponse.error) { | ||
| if ( | ||
| (profilesResponse.error as HttpError).code === StatusCodes.UNAUTHORIZED | ||
| ) { | ||
| // 401 — session invalid, redirect quietly | ||
| window.location.replace(LOGIN_ROUTE) | ||
| } else { | ||
| // all other errors (5xx, network failure, etc.) — redirect with status | ||
| // so LoginPage can surface the generic error toast on arrival. | ||
| // Fall back to 500 for network failures where no status code is present. | ||
| const statusCode = | ||
| (profilesResponse.error as HttpError).code ?? | ||
| StatusCodes.INTERNAL_SERVER_ERROR | ||
| window.location.replace(`${LOGIN_ROUTE}?status=${statusCode}`) | ||
| } | ||
| } |
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.
Problem
SelectProfilePageunconditionally redirects all errors fromuseSgidProfilesto the login page with no user feedback. Only a 401 (unauthenticated) is a valid reason to redirect silently — all other errors (5xx, other 4xx, network failures) left users stuck in a silent redirect loop with no indication that the service was at fault.Closes #9540
Solution
Gate the redirect on the error status code. Previously all errors redirected silently to
/loginwith no feedback. Now all errors redirect to/login?status=<code>, leveraging the existingLoginPagestatus-based toast mechanism to surface a user-facing message appropriate to the error type:5xx range handling and the
errors.serverErrortranslation key were added to support the new explicit server error message.Breaking Changes
Bug Fixes:
SelectProfilePage: all errors now redirect to/login?status=<code>instead of silently redirecting to/loginwith no feedback, allowingLoginPageto surface the appropriate error toast per status codeLoginPage: added 5xx range handling in the status-based toast switch — codes 500–599 now show'A server error occurred. Please try again later.'instead of the generic fallbacki18n: addederrors.serverErrortranslation key tofeatures/commonto support the explicit server error messageBefore & After Screenshots
BEFORE:
User hits a 5xx on the sgID profiles endpoint → silently redirected to
/login→ re-attempts → infinite loop, no error shownAFTER:
User hits a 500 → redirected to
/login?status=500→ toast appears:'A server error occurred. Please try again later.'Tests
useSgidProfilesinqueries.tsto throwObject.assign(new Error('Simulated 503'), { code: 503 })/login?status=503with a server error toast visible{ code: 401 }— confirm redirect lands on/login?status=401with an expired session toastnew Error('network error')(no.code) — confirm redirect lands on/login?status=500with a generic error toastqueries.tsand confirm normal sgID login flow is unaffected