Catch validation error from API

When dates chosen for billing report are not in the same
financial year, API throws an error. This error was not being
caught so far. This PR starts to catch it and display a banner
with error message on the page, instead of page crashing.
This commit is contained in:
Pea Tyczynska
2021-03-15 18:28:05 +00:00
parent 38cfee6390
commit f7142a1518

View File

@@ -285,8 +285,15 @@ def get_billing_report():
"sms_cost", "sms_fragments", "letter_cost", "letter_breakdown", "purchase_order_number",
"contact_names", "contact_email_addresses", "billing_reference"
]
result = billing_api_client.get_data_for_billing_report(start_date, end_date)
try:
result = billing_api_client.get_data_for_billing_report(start_date, end_date)
except HTTPError as e:
message = 'Date must be in a single financial year.'
if e.status_code == 400 and e.message == message:
flash(message)
return render_template('views/platform-admin/get-billing-report.html', form=form)
else:
raise e
rows = [
[
r["organisation_id"], r["organisation_name"], r["service_id"], r["service_name"],