Merge branch 'handle-new-response' into 'develop'

Handle dyanmic error message of API

See merge request soapbox-pub/soapbox-fe!1737
This commit is contained in:
Justin 2022-08-16 14:03:01 +00:00
commit a4ba081448

View file

@ -85,13 +85,15 @@ const EmailVerification = () => {
); );
}) })
.catch((error: AxiosError) => { .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 ? ( if (isEmailTaken) {
intl.formatMessage({ id: 'email_verification.exists', defaultMessage: 'This email has already been taken.' }) message = intl.formatMessage({ id: 'email_verification.exists', defaultMessage: 'This email has already been taken.' });
) : ( } else if (errorMessage) {
intl.formatMessage({ id: 'email_verification.fail', defaultMessage: 'Failed to request email verification.' }) message = errorMessage;
); }
if (isEmailTaken) { if (isEmailTaken) {
setErrors([intl.formatMessage({ id: 'email_verification.taken', defaultMessage: 'is taken' })]); setErrors([intl.formatMessage({ id: 'email_verification.taken', defaultMessage: 'is taken' })]);