Ejemplo n.º 1
0
def handle_error(exception):
    code = 500

    if isinstance(exception, ImproveDomainException):
        if isinstance(exception, EntityNotFoundException):
            code = 404
        elif isinstance(exception, BaseSecurityException):
            code = 403
        elif isinstance(exception, EntityValidationException):
            code = 422

        return jsonify(errors=exception.get_errors(), message=exception.get_message()), code

    if App.is_production_env():
        return jsonify(message='Unknown error'), code

    raise exception