2023-03-13 07:20:09 +00:00
|
|
|
from flask import jsonify, render_template, request, Response
|
|
|
|
from werkzeug.exceptions import HTTPException
|
2023-03-13 07:36:51 +00:00
|
|
|
from typing import Tuple, Union
|
2020-10-12 11:26:35 +00:00
|
|
|
|
|
|
|
|
2023-03-13 07:36:51 +00:00
|
|
|
def generic(error: HTTPException) -> Tuple[Union[str, Response], int]:
|
|
|
|
''' Generic error handler '''
|
2023-03-13 07:20:09 +00:00
|
|
|
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))
|
2023-03-13 07:36:51 +00:00
|
|
|
return response, error.code
|
2023-03-13 07:20:09 +00:00
|
|
|
return render_template('errors/error.html.j2', error=error), error.code
|