(mailboxes) manage bad secret sent to dimail API

- manage 403 returned by dimail API when mail domain secret is not valid
- improve some tests
- improve MailboxFactory to mock success for dimail API POST call
- override 403.html to return a nice failing error in django admin
- an error message is displayed on mailbox creation form of frontend
This commit is contained in:
Sabrina Demagny
2024-08-08 18:28:01 +02:00
committed by Marie
parent 5ed63fc091
commit a7a923e790
5 changed files with 132 additions and 54 deletions

View File

@@ -84,5 +84,12 @@ class DimailAPIClient:
mailbox.domain.name,
extra=extra,
)
elif response.status_code == status.HTTP_403_FORBIDDEN:
logger.error(
"[DIMAIL] 403 Forbidden: please check the mail domain secret of %s",
mailbox.domain.name,
)
raise exceptions.PermissionDenied(
f"Please check secret of the mail domain {mailbox.domain.name}"
)
return response