Skip to content

fix(login): show toast for non-401 errors on sgID profile#9768

Open
LoneRifle wants to merge 1 commit into
developfrom
fix/sgid-profile-fetch-error-handling
Open

fix(login): show toast for non-401 errors on sgID profile#9768
LoneRifle wants to merge 1 commit into
developfrom
fix/sgid-profile-fetch-error-handling

Conversation

@LoneRifle

Copy link
Copy Markdown
Contributor

Fixes #9540
Merges #9543

* 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>
@LoneRifle
LoneRifle requested review from a team and Copilot July 20, 2026 01:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.serverError to common i18n types and en-sg locale.
  • 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) parseInt should be called with an explicit radix to avoid inconsistent parsing (parseInt(statusCode ?? '', 10)). (2) The memoized callback depends on t as well as statusCode; omitting t can lead to stale translations if the language changes. Update the dependency list to include t (and any other referenced values not guaranteed stable).
import { useEffect, useMemo, useState } from 'react'

Comment thread apps/frontend/src/i18n/locales/features/common/index.ts
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}`)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] SelectProfilePage silently redirects to login on any sgID profile fetch error, causing an infinite loop

3 participants