nopaque/app/errors/handlers.py

12 lines
404 B
Python
Raw Normal View History

2022-09-02 13:07:30 +02:00
from flask import render_template, request
from werkzeug.exceptions import HTTPException
from . import bp
2020-10-12 13:26:35 +02:00
2022-09-02 13:07:30 +02:00
@bp.errorhandler(HTTPException)
def generic_error_handler(e):
2020-10-12 13:26:35 +02:00
if (request.accept_mimetypes.accept_json
and not request.accept_mimetypes.accept_html):
2022-09-02 13:07:30 +02:00
return {'errors': {'message': e.description}}, e.code
return render_template('errors/error.html.j2', error=e), e.code