mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-12-26 03:14:19 +00:00
Let the generic error handler generate json again
This commit is contained in:
parent
a1af3e34d2
commit
5c2225c43e
@ -1,5 +1,12 @@
|
|||||||
from flask import render_template
|
from flask import jsonify, render_template, request, Response
|
||||||
|
from werkzeug.exceptions import HTTPException
|
||||||
|
|
||||||
|
|
||||||
def generic_error_handler(e):
|
def generic_error_handler(error: HTTPException):
|
||||||
return render_template('errors/error.html.j2', error=e), e.code
|
accent_json: bool = request.accept_mimetypes.accept_json
|
||||||
|
accept_html: bool = request.accept_mimetypes.accept_html
|
||||||
|
if accent_json and not accept_html:
|
||||||
|
response: Response = jsonify(str(error))
|
||||||
|
response.status_code = error.code
|
||||||
|
return response
|
||||||
|
return render_template('errors/error.html.j2', error=error), error.code
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
{% block page_content %}
|
{% block page_content %}
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<h1 id="title">{{ error.name }}</h1>
|
<h1 id="title">{{ error.code }} {{ error.name }}</h1>
|
||||||
<p>{{ error.description }}</p>
|
<p>{{ error.description }}</p>
|
||||||
</div>
|
</div>
|
||||||
{% endblock page_content %}
|
{% endblock page_content %}
|
||||||
|
Loading…
Reference in New Issue
Block a user