Skip to content

Commit

Permalink
Add error handler for 400 and 500
Browse files Browse the repository at this point in the history
  • Loading branch information
greyli committed Dec 30, 2018
1 parent f7f7355 commit 64751b5
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
10 changes: 10 additions & 0 deletions app.py
Expand Up @@ -78,11 +78,21 @@ def inject_user():
return dict(user=user)


@app.errorhandler(400)
def bad_request(e):
return render_template('400.html'), 400


@app.errorhandler(404)
def page_not_found(e):
return render_template('404.html'), 404


@app.errorhandler(500)
def internal_server_error(e):
return render_template('500.html'), 500


@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
Expand Down
12 changes: 12 additions & 0 deletions templates/400.html
@@ -0,0 +1,12 @@
{% extends 'base.html' %}

{% block content %}
<ul class="movie-list">
<li>
Bad Request - 400
<span class="float-right">
<a href="{{ url_for('index') }}">Go Back</a>
</span>
</li>
</ul>
{% endblock %}
12 changes: 12 additions & 0 deletions templates/500.html
@@ -0,0 +1,12 @@
{% extends 'base.html' %}

{% block content %}
<ul class="movie-list">
<li>
Internal Server Error - 500
<span class="float-right">
<a href="{{ url_for('index') }}">Go Back</a>
</span>
</li>
</ul>
{% endblock %}

0 comments on commit 64751b5

Please sign in to comment.