nopaque/app/errors/handlers.py
2023-03-13 08:20:09 +01:00

13 lines
512 B
Python

from flask import jsonify, render_template, request, Response
from werkzeug.exceptions import HTTPException
def generic_error_handler(error: HTTPException):
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