in send flow replace suppress with try catch

suppress was suppressing 404 errors (the happy path) - but it was also
suppressing 503s from tests where we hadn't mocked endpoints
This commit is contained in:
Leo Hemsted
2018-05-03 13:35:59 +01:00
parent e8ef6fa174
commit 09a8e863a4
3 changed files with 46 additions and 33 deletions

View File

@@ -1,6 +1,5 @@
import itertools
import json
from contextlib import suppress
from string import ascii_uppercase
from zipfile import BadZipFile
@@ -479,10 +478,12 @@ def send_test_preview(service_id, template_id, filetype):
def _check_messages(service_id, template_id, upload_id, preview_row, letters_as_pdf=False):
with suppress(HTTPError):
try:
# The happy path is that the job doesnt already exist, so the
# API will return a 404 and the client will raise HTTPError.
job_api_client.get_job(service_id, upload_id)
# the job exists already - so go back to the templates page
# If we just return a `redirect` (302) object here, we'll get
# errors when we try and unpack in the check_messages route.
# Rasing a werkzeug.routing redirect means that doesn't happen.
@@ -491,6 +492,9 @@ def _check_messages(service_id, template_id, upload_id, preview_row, letters_as_
service_id=service_id,
template_id=template_id
))
except HTTPError as e:
if e.status_code != 404:
raise
users = user_api_client.get_users_for_service(service_id=service_id)