Skip to content
Open
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
7 changes: 6 additions & 1 deletion apps/frontend/src/features/login/LoginPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,13 @@ export const LoginPage = (): JSX.Element => {
return t('features.login.LoginPage.forbidden')
case StatusCodes.UNAUTHORIZED.toString():
return t('features.login.LoginPage.expiredSession')
default:
default: {
const code = parseInt(statusCode ?? '')
if (code >= 500 && code < 600) {
return t('features.common.errors.serverError')
}
return t('features.common.errors.generic')
}
}
}, [statusCode])

Expand Down
18 changes: 16 additions & 2 deletions apps/frontend/src/features/login/SelectProfilePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { DASHBOARD_ROUTE, LOGIN_ROUTE } from '~constants/routes'
import { useIsMobile } from '~hooks/useIsMobile'
import { useLocalStorage } from '~hooks/useLocalStorage'
import { useToast } from '~hooks/useToast'
import { ApiService } from '~services/ApiService'
import { ApiService, HttpError } from '~services/ApiService'
import Button from '~components/Button'
import { ModalCloseButton } from '~components/Modal'

Expand Down Expand Up @@ -132,7 +132,21 @@ export const SelectProfilePage = (): JSX.Element => {
// 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}`)
}
}
Comment on lines 132 to +149

useEffect(() => {
if (profilesResponse.data?.profiles.length === 0) {
Expand Down
1 change: 1 addition & 0 deletions apps/frontend/src/i18n/locales/features/common/en-sg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export const enSG: Common = {
},
pageNotFound: 'This page could not be found.',
generic: 'Something went wrong. Please try again later.',
serverError: 'A server error occurred. Please try again later.',
},
tooltip: {
deleteField: 'Delete field',
Expand Down
1 change: 1 addition & 0 deletions apps/frontend/src/i18n/locales/features/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export interface Common {
}
pageNotFound: string
generic: string
serverError: string
}
Comment thread
LoneRifle marked this conversation as resolved.
tooltip: {
deleteField: string
Expand Down
Loading