diff --git a/src/backend/mailbox_manager/api/client/serializers.py b/src/backend/mailbox_manager/api/client/serializers.py index ceca66dec..c01fd44c6 100644 --- a/src/backend/mailbox_manager/api/client/serializers.py +++ b/src/backend/mailbox_manager/api/client/serializers.py @@ -1,7 +1,9 @@ """Client serializers for People's mailbox manager app.""" import json +from logging import getLogger +from requests.exceptions import HTTPError from rest_framework import exceptions, serializers from core.api.client.serializers import UserSerializer @@ -10,6 +12,8 @@ from mailbox_manager import enums, models from mailbox_manager.utils.dimail import DimailAPIClient +logger = getLogger(__name__) + class MailboxSerializer(serializers.ModelSerializer): """Serialize mailbox.""" @@ -194,10 +198,13 @@ def create(self, validated_data): enums.MailDomainRoleChoices.ADMIN, enums.MailDomainRoleChoices.OWNER, ]: - dimail.create_user(validated_data["user"].sub) - dimail.create_allow( - validated_data["user"].sub, validated_data["domain"].name - ) + try: + dimail.create_user(validated_data["user"].sub) + dimail.create_allow( + validated_data["user"].sub, validated_data["domain"].name + ) + except HTTPError: + logger.error("[DIMAIL] access creation failed %s") return super().create(validated_data)