nopaque/app/errors/handlers.py

12 lines
404 B
Python
Raw Normal View History

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