mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 07:35:34 -05:00
Merge pull request #3359 from alphagov/improve-clarify-botocore-exception-180017131
Improve and clarify large task error handling
This commit is contained in:
@@ -232,9 +232,10 @@ def process_sms_or_email_notification(
|
|||||||
reply_to_text=reply_to_text
|
reply_to_text=reply_to_text
|
||||||
)
|
)
|
||||||
return resp
|
return resp
|
||||||
except botocore.exceptions.ClientError:
|
except (botocore.exceptions.ClientError, botocore.parsers.ResponseParserError):
|
||||||
# if SQS cannot put the task on the queue, it's probably because the notification body was too long and it
|
# If SQS cannot put the task on the queue, it's probably because the notification body was too long and it
|
||||||
# went over SQS's 256kb message limit. If so, we
|
# went over SQS's 256kb message limit. If the body is very large, it may exceed the HTTP max content length;
|
||||||
|
# the exception we get here isn't handled correctly by botocore - we get a ResponseParserError instead.
|
||||||
current_app.logger.info(
|
current_app.logger.info(
|
||||||
f'Notification {notification_id} failed to save to high volume queue. Using normal flow instead'
|
f'Notification {notification_id} failed to save to high volume queue. Using normal flow instead'
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1068,13 +1068,21 @@ def test_post_notifications_saves_email_or_sms_to_queue(client, notify_db_sessio
|
|||||||
assert len(Notification.query.all()) == 0
|
assert len(Notification.query.all()) == 0
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("exception", [
|
||||||
|
botocore.exceptions.ClientError({'some': 'json'}, 'some opname'),
|
||||||
|
botocore.parsers.ResponseParserError('exceeded max HTTP body length'),
|
||||||
|
])
|
||||||
@pytest.mark.parametrize("notification_type", ("email", "sms"))
|
@pytest.mark.parametrize("notification_type", ("email", "sms"))
|
||||||
def test_post_notifications_saves_email_or_sms_normally_if_saving_to_queue_fails(
|
def test_post_notifications_saves_email_or_sms_normally_if_saving_to_queue_fails(
|
||||||
client, notify_db_session, mocker, notification_type
|
client,
|
||||||
|
notify_db_session,
|
||||||
|
mocker,
|
||||||
|
notification_type,
|
||||||
|
exception
|
||||||
):
|
):
|
||||||
save_task = mocker.patch(
|
save_task = mocker.patch(
|
||||||
f"app.celery.tasks.save_api_{notification_type}.apply_async",
|
f"app.celery.tasks.save_api_{notification_type}.apply_async",
|
||||||
side_effect=botocore.exceptions.ClientError({'some': 'json'}, 'some opname')
|
side_effect=exception,
|
||||||
)
|
)
|
||||||
mock_send_task = mocker.patch(f'app.celery.provider_tasks.deliver_{notification_type}.apply_async')
|
mock_send_task = mocker.patch(f'app.celery.provider_tasks.deliver_{notification_type}.apply_async')
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user