mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-15 01:05:42 +00:00
14 lines
570 B
Python
14 lines
570 B
Python
from flask import jsonify, render_template, request, Response
|
|
from werkzeug.exceptions import HTTPException
|
|
from typing import Tuple, Union
|
|
|
|
|
|
def generic(error: HTTPException) -> Tuple[Union[str, Response], int]:
|
|
''' Generic error handler '''
|
|
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))
|
|
return response, error.code
|
|
return render_template('errors/error.html.j2', error=error), error.code
|