From 413c6c4c2653deba6692bed74deeb0bb8c4c7f37 Mon Sep 17 00:00:00 2001 From: Ben Thorner Date: Tue, 12 Apr 2022 15:51:06 +0100 Subject: [PATCH] Move check for existing letter earlier in endpoint In response to: [^1]. [^1]: https://github.com/alphagov/notifications-api/pull/3503#discussion_r848426047 --- app/service/send_notification.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/service/send_notification.py b/app/service/send_notification.py index 119f0a38d..28208eea8 100644 --- a/app/service/send_notification.py +++ b/app/service/send_notification.py @@ -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