️(fix) add error when mailbox create failed (#915)

fix toast error when mailbox create failed
This commit is contained in:
elvoisin
2025-06-10 14:19:31 +02:00
committed by GitHub
parent 95f63fa56d
commit 1245c54c61
4 changed files with 39 additions and 6 deletions

View File

@@ -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

View File

@@ -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,
});
}
};

View File

@@ -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')}

View File

@@ -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);
},
});