From 249ae41c24d99f899e2956162d26fda9561fe7da Mon Sep 17 00:00:00 2001 From: Athanasios Voutsadakis Date: Thu, 8 Mar 2018 17:49:08 +0000 Subject: [PATCH] Add error handling This adds an /error/XXX endpoint that triggers the corresponding XXX error code and its handling. Related: https://github.com/alphagov/notifications-aws/pull/331 --- app/__init__.py | 4 ++++ app/main/views/index.py | 7 ++++++- app/templates/error/413.html | 21 +++++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 app/templates/error/413.html diff --git a/app/__init__.py b/app/__init__.py index c9d2242f6..2314647e4 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -488,6 +488,10 @@ def register_errorhandlers(application): # noqa (C901 too complex) def handle_gone(error): return _error_response(410) + @application.errorhandler(413) + def handle_payload_too_large(error): + return _error_response(413) + @application.errorhandler(404) def handle_not_found(error): return _error_response(404) diff --git a/app/main/views/index.py b/app/main/views/index.py index a00ab5523..5665d1421 100644 --- a/app/main/views/index.py +++ b/app/main/views/index.py @@ -1,4 +1,4 @@ -from flask import redirect, render_template, request, url_for +from flask import redirect, render_template, request, url_for, abort from flask_login import current_user, login_required from notifications_utils.international_billing_rates import ( INTERNATIONAL_BILLING_RATES, @@ -18,6 +18,11 @@ def index(): return render_template('views/signedout.html') +@main.route('/error/') +def error(status_code): + abort(status_code) + + @main.route("/verify-mobile") @login_required def verify_mobile(): diff --git a/app/templates/error/413.html b/app/templates/error/413.html new file mode 100644 index 000000000..4dfddc603 --- /dev/null +++ b/app/templates/error/413.html @@ -0,0 +1,21 @@ +{% extends "withoutnav_template.html" %} +{% block per_page_title %}File too big{% endblock %} +{% block maincolumn_content %} +
+
+

+ The file you uploaded was too big +

+
+
+

+ Files must be smaller than 5 MB. +

+

+ Go back and try again. +

+
+
+
+
+{% endblock %}