From 35d32e73919d63966400588bf50bac2ac00a59cc Mon Sep 17 00:00:00 2001 From: Justin Date: Tue, 16 Aug 2022 09:48:58 -0400 Subject: [PATCH] Handle dyanmic error message of API --- .../verification/steps/email-verification.tsx | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/app/soapbox/features/verification/steps/email-verification.tsx b/app/soapbox/features/verification/steps/email-verification.tsx index 01e023456..bec6c2868 100644 --- a/app/soapbox/features/verification/steps/email-verification.tsx +++ b/app/soapbox/features/verification/steps/email-verification.tsx @@ -85,13 +85,15 @@ const EmailVerification = () => { ); }) .catch((error: AxiosError) => { - const isEmailTaken = (error.response?.data as any)?.error === 'email_taken'; + const errorMessage = (error.response?.data as any)?.error; + const isEmailTaken = errorMessage === 'email_taken'; + let message = intl.formatMessage({ id: 'email_verification.fail', defaultMessage: 'Failed to request email verification.' }); - const message = isEmailTaken ? ( - intl.formatMessage({ id: 'email_verification.exists', defaultMessage: 'This email has already been taken.' }) - ) : ( - intl.formatMessage({ id: 'email_verification.fail', defaultMessage: 'Failed to request email verification.' }) - ); + if (isEmailTaken) { + message = intl.formatMessage({ id: 'email_verification.exists', defaultMessage: 'This email has already been taken.' }); + } else if (errorMessage) { + message = errorMessage; + } if (isEmailTaken) { setErrors([intl.formatMessage({ id: 'email_verification.taken', defaultMessage: 'is taken' })]);