2023-05-15 12:00:13 +02:00
|
|
|
from flask import jsonify, render_template, request
|
2023-03-13 08:20:09 +01:00
|
|
|
from werkzeug.exceptions import HTTPException
|
2023-05-15 12:00:13 +02:00
|
|
|
from . import bp
|
2020-10-12 13:26:35 +02:00
|
|
|
|
|
|
|
|
2023-05-15 12:00:13 +02:00
|
|
|
@bp.app_errorhandler(HTTPException)
|
|
|
|
def handle_http_exception(error):
|
|
|
|
''' Generic HTTP exception handler '''
|
|
|
|
accept_json = request.accept_mimetypes.accept_json
|
|
|
|
accept_html = request.accept_mimetypes.accept_html
|
|
|
|
if accept_json and not accept_html:
|
|
|
|
response = jsonify(str(error))
|
2023-03-13 08:36:51 +01:00
|
|
|
return response, error.code
|
2023-03-13 08:20:09 +01:00
|
|
|
return render_template('errors/error.html.j2', error=error), error.code
|