Fix __str__ not returning a String for KeystoneException

KeystoneExcepion is only created with the Exception returned by
Keystone. However, since it was derived from BaseException, __init__
expected a message not an Exception. This caused:

TypeError: __str__ returned non-string (type AuthorizationFailure)

if you tried to print out the resulting KeystoneException.

Fixed this by deriving from Exception which knows how to handle an
Exception passed in

Change-Id: I6450b59f5ccd32d34ea3e531098eeebfcb36196e
This commit is contained in:
Craig Bryant 2016-07-12 13:18:06 -06:00
parent 834d7c740e
commit c519767a55
1 changed files with 6 additions and 12 deletions

View File

@ -1,4 +1,4 @@
# (C) Copyright 2014-2016 Hewlett Packard Enterprise Development Company LP
# (C) Copyright 2014-2016 Hewlett Packard Enterprise Development LP
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@ -54,19 +54,13 @@ class RequestTimeoutError(BaseException):
"""Timeout making a POST, GET, PATCH, DELETE, or PUT request to the server."""
class KeystoneException(BaseException):
class KeystoneException(Exception):
"""Base exception for all Keystone-derived exceptions."""
code = 'N/A'
def __init__(self, message=None):
super(KeystoneException, self).__init__(message)
try:
log.error("exception: {}".format(message))
self.error = jsonutils.loads(message)
except Exception:
self.error = {'error':
{'message': self.message or self.__class__.__doc__}}
# This is initialized with the exception raised by the Keystone client so
# deriving this class from Exception instead of BaseException allows that to
# be handled without any additional code
pass
class HTTPException(BaseException):