Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sign-up.page): convert generic backend error to more specific #1646

Merged
merged 1 commit into from
May 27, 2022
Merged
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
26 changes: 24 additions & 2 deletions src/app/features/signup/signup.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,30 @@ export class SignupPage {
)
),
catchError((err: unknown) => {
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
if (err instanceof HttpErrorResponse && err.status === 400) {
if (
err instanceof HttpErrorResponse &&
err.error.error?.type === 'duplicate_email'
) {
return this.errorService.toastError$(
this.translocoService.translate(
'error.diaBackend.duplicate_email'
)
);
}
if (
err instanceof HttpErrorResponse &&
err.error.error?.details?.username?.length > 0
) {
return this.errorService.toastError$(
this.translocoService.translate(
'error.diaBackend.duplicate_username'
)
);
}
if (
err instanceof HttpErrorResponse &&
err.error.error?.type === 'invalid_referral_code'
) {
return this.errorService.toastError$(
this.translocoService.translate(
'error.diaBackend.invalid_referral_code'
Expand Down
1 change: 1 addition & 0 deletions src/app/shared/error/error.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export class ErrorService {
timeoutError,
unknownError,
}) => {
// eslint-disable-next-line no-debugger
if (typeof error === 'string') return error;
if (error instanceof HttpErrorResponse) {
if (error.status === HttpErrorCode.INVALID)
Expand Down
4 changes: 3 additions & 1 deletion src/assets/i18n/en-us.json
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,9 @@
"unable_to_confirm_order": "Unable to confirm order. Please try again.",
"unpaid_num_exceed_threshold": "Too much unpaid NUM. Please contact us with email to restore account functionality.",
"invalid_network_app_name": "Invalid network app.",
"invalid_referral_code": "Invalide referral code"
"invalid_referral_code": "Invalid referral code",
"duplicate_email": "The email has already been registered",
"duplicate_username": "User with this username already exists"
},
"wallets": {
"emptyTransferAmount": "Please enter a valid transfer amount.",
Expand Down
4 changes: 3 additions & 1 deletion src/assets/i18n/zh-tw.json
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,9 @@
"unable_to_confirm_order": "無法確認訂單。請再試一次。",
"unpaid_num_exceed_threshold": "太多未付的 NUM。請通過電子郵件與我們聯繫以恢復帳戶功能。",
"invalid_network_app_name": "無效的網絡動作。",
"invalid_referral_code": "無效的推薦代碼"
"invalid_referral_code": "無效的推薦代碼",
"duplicate_email": "該電子郵件已註冊",
"duplicate_username": "用戶名已被其他使用者使用"
},
"wallets": {
"emptyTransferAmount": "請輸入有效轉帳金額。",
Expand Down