🐛(dimail) add status code in case of unexpected error

add status code in case of unexpected error
This commit is contained in:
Marie PUPO JEAMMET
2024-10-03 19:04:08 +02:00
committed by Marie
parent ce21a7552b
commit 579657afa4
2 changed files with 14 additions and 3 deletions

View File

@@ -500,7 +500,8 @@ def test_api_mailboxes__user_unrelated_to_domain():
assert not models.Mailbox.objects.exists()
def test_api_mailboxes__handling_dimail_unexpected_error():
@mock.patch.object(Logger, "error")
def test_api_mailboxes__handling_dimail_unexpected_error(mock_error):
"""
API should raise a clear error when dimail returns an unexpected response.
"""
@@ -542,6 +543,12 @@ def test_api_mailboxes__handling_dimail_unexpected_error():
}
assert not models.Mailbox.objects.exists()
# Check error logger was called
assert mock_error.called
assert mock_error.call_args_list[1][0] == (
'Unexpected response from dimail: 500 {"details": "Internal server error"}',
)
@mock.patch.object(Logger, "error")
@mock.patch.object(Logger, "info")

View File

@@ -120,8 +120,12 @@ class DimailAPIClient:
"""Raise error when encountering an unexpected error in dimail."""
error_content = response.content.decode("utf-8")
logger.error("[DIMAIL] unexpected error : %s", error_content)
raise SystemError(f"Unexpected response from dimail: {error_content}")
logger.error(
"[DIMAIL] unexpected error : %s %s", response.status_code, error_content
)
raise SystemError(
f"Unexpected response from dimail: {response.status_code} {error_content}"
)
def send_new_mailbox_notification(self, recipient, mailbox_data):
"""