⚡️(fix) add error when mailbox create failed (#915)
fix toast error when mailbox create failed
This commit is contained in:
@@ -10,6 +10,7 @@ and this project adheres to
|
||||
|
||||
### Added
|
||||
|
||||
- ⚡️(fix) add error when mailbox create failed
|
||||
- ✨(mailbox) allow to reset password on mailboxes #834
|
||||
|
||||
## [1.16.0] - 2025-05-05
|
||||
|
||||
@@ -26,10 +26,13 @@ export const createMailbox = async ({
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new APIError(
|
||||
'Failed to create the mailbox',
|
||||
await errorCauses(response),
|
||||
);
|
||||
const errorData = await errorCauses(response);
|
||||
console.log('Error data:', errorData);
|
||||
throw new APIError('Failed to create the mailbox', {
|
||||
status: errorData.status,
|
||||
cause: errorData.cause as string[],
|
||||
data: errorData.data,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -127,7 +127,6 @@ export function MailBoxesView({ mailDomain }: { mailDomain: MailDomain }) {
|
||||
<Button
|
||||
data-testid="button-new-mailbox"
|
||||
onClick={openModal}
|
||||
icon={<span className="material-icons">add</span>}
|
||||
disabled={!isCreateMailboxFormVisible}
|
||||
>
|
||||
{t('New mail address')}
|
||||
|
||||
@@ -66,7 +66,37 @@ export const ModalCreateMailbox = ({
|
||||
closeModal();
|
||||
},
|
||||
onError: (error) => {
|
||||
const causes = parseAPIError({ error }) || [];
|
||||
const causes =
|
||||
parseAPIError({
|
||||
error,
|
||||
errorParams: [
|
||||
[
|
||||
['Mailbox with this Local_part and Domain already exists'],
|
||||
t('This email prefix is already used.'),
|
||||
undefined,
|
||||
],
|
||||
[
|
||||
['Invalid format'],
|
||||
t('Invalid format for the email prefix.'),
|
||||
undefined,
|
||||
],
|
||||
],
|
||||
serverErrorParams: [
|
||||
t(
|
||||
'An error occurred while creating the mailbox. Please try again.',
|
||||
),
|
||||
undefined,
|
||||
],
|
||||
}) || [];
|
||||
if (causes.length > 0) {
|
||||
causes.forEach((cause) => {
|
||||
toast(cause, VariantType.ERROR, { duration: 4000 });
|
||||
});
|
||||
} else {
|
||||
toast(t('Mailbox create failed!'), VariantType.ERROR, {
|
||||
duration: 4000,
|
||||
});
|
||||
}
|
||||
setErrorCauses(causes);
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user