mirror of
https://github.com/shouptech/humulus.git
synced 2026-02-03 16:09:44 +00:00
parent
de9f4f1e68
commit
95e5a35295
2 changed files with 43 additions and 1 deletions
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from flask import Flask
|
from flask import Flask, render_template
|
||||||
|
|
||||||
|
|
||||||
def create_app(test_config=None):
|
def create_app(test_config=None):
|
||||||
|
|
@ -55,4 +55,22 @@ def create_app(test_config=None):
|
||||||
from . import filters
|
from . import filters
|
||||||
filters.create_filters(app)
|
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
|
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
|
||||||
|
)
|
||||||
|
|
|
||||||
24
src/humulus/templates/_error.html
Normal file
24
src/humulus/templates/_error.html
Normal file
|
|
@ -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 %}
|
||||||
|
<div class="text-center">
|
||||||
|
<img src="https://http.cat/{{ code }}" alt="{{ message }}">
|
||||||
|
<p>Error messages from <a href="https://http.cat/">HTTP Cats</a></p>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
Loading…
Add table
Reference in a new issue