From 198a619ffbb185ccc8995ae1de61772e35c3d822 Mon Sep 17 00:00:00 2001 From: Andrew Leith Date: Wed, 18 Dec 2024 16:24:14 +0000 Subject: [PATCH 1/4] fix(start_job): add exception handling in case API throws an annual limits error at this point; update the expected error message strings --- app/main/views/send.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/app/main/views/send.py b/app/main/views/send.py index 53acc9ba63..eaf88d5252 100644 --- a/app/main/views/send.py +++ b/app/main/views/send.py @@ -888,8 +888,12 @@ def check_notification_preview(service_id, template_id, filetype): @main.route("/services//start-job/", methods=["POST"]) @user_has_permissions("send_messages", restrict_admin_usage=True) def start_job(service_id, upload_id): - job_api_client.create_job(upload_id, service_id, scheduled_for=request.form.get("scheduled_for", "")) - + try: + job_api_client.create_job(upload_id, service_id, scheduled_for=request.form.get("scheduled_for", "")) + except HTTPError as exception: + return render_template( + "views/notifications/check.html", **(get_template_error_dict(exception) if exception else {}), template=None + ) session.pop("sender_id", None) return redirect( @@ -1107,11 +1111,12 @@ def get_template_error_dict(exception): error = "too-many-sms-messages" elif "Content for template has a character count greater than the limit of" in exception.message: error = "message-too-long" - elif "Exceeded annual email sending limit" in exception.message: + elif "Exceeded annual email sending" in exception.message: error = "too-many-email-annual" - elif "Exceeded annual SMS sending limit" in exception.message: + elif "Exceeded annual SMS sending" in exception.message: error = "too-many-sms-annual" else: + current_app.logger.error("Unhandled exception from API: {}".format(exception)) raise exception return { From 60d6426c16ee75810d6e898f6f3b0cf195b4106a Mon Sep 17 00:00:00 2001 From: Andrew Leith Date: Wed, 18 Dec 2024 16:24:36 +0000 Subject: [PATCH 2/4] fix(check.html): don't render the template preview in the case of an API exception --- app/templates/views/notifications/check.html | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/templates/views/notifications/check.html b/app/templates/views/notifications/check.html index 0161a74f17..e9d61b7f94 100644 --- a/app/templates/views/notifications/check.html +++ b/app/templates/views/notifications/check.html @@ -88,7 +88,9 @@

{{_('You cannot send this email message today') }}
Date: Wed, 18 Dec 2024 17:09:42 +0000 Subject: [PATCH 4/4] fix: pass time_to_reset into the view --- app/main/views/send.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/main/views/send.py b/app/main/views/send.py index eaf88d5252..f0e4e86406 100644 --- a/app/main/views/send.py +++ b/app/main/views/send.py @@ -892,7 +892,10 @@ def start_job(service_id, upload_id): job_api_client.create_job(upload_id, service_id, scheduled_for=request.form.get("scheduled_for", "")) except HTTPError as exception: return render_template( - "views/notifications/check.html", **(get_template_error_dict(exception) if exception else {}), template=None + "views/notifications/check.html", + time_to_reset=get_limit_reset_time_et(), + **(get_template_error_dict(exception) if exception else {}), + template=None, ) session.pop("sender_id", None)