Skip to content

Commit

Permalink
Merge pull request #1646 from numbersprotocol/fix-sign-up-error-message
Browse files Browse the repository at this point in the history
fix(sign-up.page): convert generic backend error to more specific
  • Loading branch information
sultanmyrza authored May 27, 2022
2 parents fd79cb2 + 759cc4b commit cd99e5a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
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

0 comments on commit cd99e5a

Please sign in to comment.