2017-11-02 06:43:40 +00:00
|
|
|
from flask import render_template, request
|
2017-10-09 07:09:22 +00:00
|
|
|
from app import db
|
|
|
|
from app.errors import bp
|
2017-11-02 06:43:40 +00:00
|
|
|
from app.api.errors import error_response as api_error_response
|
|
|
|
|
|
|
|
|
|
|
|
def wants_json_response():
|
|
|
|
return request.accept_mimetypes['application/json'] >= \
|
|
|
|
request.accept_mimetypes['text/html']
|
2017-10-09 07:09:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
@bp.app_errorhandler(404)
|
|
|
|
def not_found_error(error):
|
2017-11-02 06:43:40 +00:00
|
|
|
if wants_json_response():
|
|
|
|
return api_error_response(404)
|
2017-10-09 07:09:22 +00:00
|
|
|
return render_template('errors/404.html'), 404
|
|
|
|
|
|
|
|
|
|
|
|
@bp.app_errorhandler(500)
|
|
|
|
def internal_error(error):
|
|
|
|
db.session.rollback()
|
2017-11-02 06:43:40 +00:00
|
|
|
if wants_json_response():
|
|
|
|
return api_error_response(500)
|
2017-10-09 07:09:22 +00:00
|
|
|
return render_template('errors/500.html'), 500
|