Error handler for schema validation errors

This commit is contained in:
Rebecca Law
2016-10-31 15:43:11 +00:00
parent fc298367c5
commit a358f3cb3a
2 changed files with 33 additions and 3 deletions

View File

@@ -1,5 +1,8 @@
import json
from flask import jsonify, current_app
from sqlalchemy.exc import SQLAlchemyError, DataError
from jsonschema import ValidationError
from sqlalchemy.exc import DataError
from sqlalchemy.orm.exc import NoResultFound
from app.authentication.auth import AuthError
@@ -35,6 +38,11 @@ def register_errors(blueprint):
response = jsonify(error.to_dict_v2()), error.status_code
return response
@blueprint.errorhandler(ValidationError)
def validation_error(error):
current_app.logger.exception(error)
return jsonify(json.loads(error.message)), 400
@blueprint.errorhandler(NoResultFound)
@blueprint.errorhandler(DataError)
def no_result_found(e):