Add more default messages

This commit is contained in:
Joseph Schorr 2014-01-24 15:26:32 -05:00
parent 374754c9c9
commit 0d84cfdf17

View file

@ -7,20 +7,21 @@ logger = logging.getLogger(__name__)
DEFAULT_MESSAGE = {}
DEFAULT_MESSAGE[400] = 'Invalid Request'
DEFAULT_MESSAGE[401] = 'Unauthorized'
DEFAULT_MESSAGE[403] = 'Permission Denied'
DEFAULT_MESSAGE[404] = 'Not Found'
DEFAULT_MESSAGE[409] = 'Conflict'
def abort(status_code, message=None, **kwargs):
message = str(message) % kwargs if message else DEFAULT_MESSAGE[status_code]
message = str(message) % kwargs if message else DEFAULT_MESSAGE.get(status_code, '')
if status_code == 403:
# Add the user information.
auth_user = get_authenticated_user()
auth_token = get_validated_token()
if auth_user:
message = '%s (user: %s)' % (message, auth_user.username)
elif auth_token:
message = '%s (token: %s)' % (message, auth_token.friendly_name or auth_token.code)
# Add the user information.
auth_user = get_authenticated_user()
auth_token = get_validated_token()
if auth_user:
message = '%s (user: %s)' % (message, auth_user.username)
elif auth_token:
message = '%s (token: %s)' % (message, auth_token.friendly_name or auth_token.code)
# Log the abort.
logger.error('Error %s: %s. Arguments: %s' % (status_code, message, request.view_args))