refactored the requires_auth handler to raise exceptions

hopefully cleans up code flow and readability [a tiny bit].
raise an AuthException in auth.py, and catch it in errors.py to
save on returning error_repsonse values throughout the function
This commit is contained in:
Leo Hemsted
2016-06-29 17:37:20 +01:00
parent 39519e3f36
commit 3838715077
3 changed files with 51 additions and 35 deletions

View File

@@ -5,6 +5,7 @@ from flask import (
from sqlalchemy.exc import SQLAlchemyError, DataError
from sqlalchemy.orm.exc import NoResultFound
from marshmallow import ValidationError
from app.authentication.auth import AuthError
class InvalidRequest(Exception):
@@ -23,6 +24,10 @@ class InvalidRequest(Exception):
def register_errors(blueprint):
@blueprint.app_errorhandler(AuthError)
def authentication_error(error):
return jsonify(result='error', message=error.message), error.code
@blueprint.app_errorhandler(ValidationError)
def validation_error(error):
current_app.logger.error(error)