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
20 changes: 18 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,23 @@ 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) {
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}`)
}
}
Comment on lines +136 to +151

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
}
tooltip: {
deleteField: string
Expand Down
Loading