diff --git a/src/humulus/app.py b/src/humulus/app.py index df149fb..0e078b0 100644 --- a/src/humulus/app.py +++ b/src/humulus/app.py @@ -16,7 +16,7 @@ import os -from flask import Flask +from flask import Flask, render_template def create_app(test_config=None): @@ -55,4 +55,22 @@ def create_app(test_config=None): from . import filters filters.create_filters(app) + # Register custom error handlers + app.register_error_handler(400, bad_request) + app.register_error_handler(404, page_not_found) + return app + + +def bad_request(e): + return ( + render_template('_error.html', code=400, message='400 Bad Request'), + 400 + ) + + +def page_not_found(e): + return ( + render_template('_error.html', code=404, message='404 Not Found'), + 404 + ) diff --git a/src/humulus/templates/_error.html b/src/humulus/templates/_error.html new file mode 100644 index 0000000..8afdaab --- /dev/null +++ b/src/humulus/templates/_error.html @@ -0,0 +1,24 @@ +{#- + Copyright 2019 Mike Shoup + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +-#} +{% extends '_base.html' %} +{% block title %}Home{% endblock %} + +{% block body %} +
Error messages from HTTP Cats
+