Move check for existing letter earlier in endpoint

In response to: [^1].

[^1]: https://github.com/alphagov/notifications-api/pull/3503#discussion_r848426047
This commit is contained in:
Ben Thorner
2022-04-12 15:51:06 +01:00
parent 70430f10ea
commit 413c6c4c26

View File

@@ -169,6 +169,10 @@ def send_pdf_letter_notification(service_id, post_data):
allow_guest_list_recipients=False,
)
# notification already exists e.g. if the user clicked send in different tabs
if get_notification_by_id(post_data['file_id']):
return {'id': str(post_data['file_id'])}
template = get_precompiled_letter_template(service.id)
file_location = 'service-{}/{}.pdf'.format(service.id, post_data['file_id'])
@@ -179,10 +183,6 @@ def send_pdf_letter_notification(service_id, post_data):
post_data['file_id'], current_app.config['TRANSIENT_UPLOADED_LETTERS'])
)
# notification already exists e.g. if the user clicked send in different tabs
if get_notification_by_id(post_data['file_id']):
return {'id': str(post_data['file_id'])}
raise e
# Getting the page count won't raise an error since admin has already checked the PDF is valid