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:
commit
a4ba081448
1 changed files with 8 additions and 6 deletions
|
@ -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' })]);
|
||||||
|
|
Loading…
Reference in a new issue