You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
944 B
Python
32 lines
944 B
Python
from flask import request, render_template
|
|
|
|
from iti.applications.common.utils import fail
|
|
|
|
|
|
def _wants_html() -> bool:
|
|
return (
|
|
request.accept_mimetypes.accept_html
|
|
and request.accept_mimetypes["text/html"]
|
|
>= request.accept_mimetypes["application/json"]
|
|
)
|
|
|
|
|
|
def init_error_views(app):
|
|
@app.errorhandler(403)
|
|
def forbidden(error):
|
|
if not _wants_html():
|
|
return fail(message="Forbidden", code=403), 200
|
|
return render_template("errors/403.html"), 403
|
|
|
|
@app.errorhandler(404)
|
|
def page_not_found(error):
|
|
if not _wants_html():
|
|
return fail(message="Not Found", code=404), 200
|
|
return render_template("errors/404.html"), 404
|
|
|
|
@app.errorhandler(500)
|
|
def internal_server_error(error):
|
|
if not _wants_html():
|
|
return fail(message="Internal Server Error", code=500), 200
|
|
return render_template("errors/500.html"), 500
|