Add 503 error handler

This commit is contained in:
Patrick Jentsch 2021-11-15 14:36:18 +01:00
parent f711eec53b
commit 70d541690f
2 changed files with 29 additions and 0 deletions

View File

@ -40,3 +40,13 @@ def internal_server_error(e):
response.status_code = 500
return response
return render_template('errors/500.html.j2', title='Internal Server Error'), 500
@bp.app_errorhandler(503)
def service_unavailable_error(e):
if (request.accept_mimetypes.accept_json
and not request.accept_mimetypes.accept_html):
response = jsonify({'error': 'service unavailable'})
response.status_code = 503
return response
return render_template('errors/503.html.j2', title='Service Unavailable'), 503

View File

@ -0,0 +1,19 @@
{% extends "base.html.j2" %}
{% block page_content %}
<div class="container">
<h1 id="title">{{ title }}</h1>
<p class="light">{{ request.path }}</p>
<p>Alternatively, you can visit the <a href="{{ url_for('main.index') }}">Main Page</a> or read <a class="modal-trigger" href="#more-information-modal">more information</a> about this type of error.</p>
</div>
<div class="modal" id="more-information-modal">
<div class="modal-content">
<h2>About the "{{ title }}" error</h2>
<p>The server cannot handle the request (because it is overloaded or down for maintenance). Generally, this is a temporary state.</p>
</div>
<div class="modal-footer">
<a href="#!" class="btn-flat modal-close waves-effect waves-green">Close</a>
</div>
</div>
{% endblock page_content %}