Use human readable exception messages
Currently, the exceptions are nothing if converted to strings. The doc strings are human reable and useful to users, so use them. Before: $ python examples/connection.py ERROR: Exception raised: $ After: $ python examples/connection.py ERROR: Exception raised: Could not find requested endpoint in Service Catalog. $ Change-Id: I1300e411c93bdfb17975e4f61e925b5b6474434c
This commit is contained in:
parent
2ab831ce6f
commit
c7f60421a0
@ -14,5 +14,4 @@ from keystoneauth1.exceptions import base
|
||||
|
||||
|
||||
class AuthorizationFailure(base.ClientException):
|
||||
"""Cannot authorize API client."""
|
||||
pass
|
||||
message = "Cannot authorize API client."
|
||||
|
@ -14,11 +14,11 @@ from keystoneauth1.exceptions import base
|
||||
|
||||
|
||||
class AuthPluginException(base.ClientException):
|
||||
"""Something went wrong with auth plugins."""
|
||||
message = "Something went wrong with auth plugins."
|
||||
|
||||
|
||||
class MissingAuthPlugin(AuthPluginException):
|
||||
"""An authenticated request is required but no plugin available."""
|
||||
message = "An authenticated request is required but no plugin available."
|
||||
|
||||
|
||||
class NoMatchingPlugin(AuthPluginException):
|
||||
|
@ -16,3 +16,12 @@ __all__ = ['ClientException']
|
||||
|
||||
class ClientException(Exception):
|
||||
"""The base exception for everything to do with clients."""
|
||||
message = None
|
||||
|
||||
def __init__(self, message=None):
|
||||
if not message:
|
||||
if self.message:
|
||||
message = self.message
|
||||
else:
|
||||
message = self.__class__.__name__
|
||||
super(Exception, self).__init__(message)
|
||||
|
@ -19,14 +19,12 @@ __all__ = ['CatalogException',
|
||||
|
||||
|
||||
class CatalogException(base.ClientException):
|
||||
"""Something is rotten in Service Catalog."""
|
||||
message = "Something is rotten in Service Catalog."
|
||||
|
||||
|
||||
class EndpointNotFound(CatalogException):
|
||||
"""Could not find requested endpoint in Service Catalog."""
|
||||
pass
|
||||
message = "Could not find requested endpoint in Service Catalog."
|
||||
|
||||
|
||||
class EmptyCatalog(EndpointNotFound):
|
||||
"""The service catalog is empty."""
|
||||
pass
|
||||
message = "The service catalog is empty."
|
||||
|
@ -26,23 +26,19 @@ class RetriableConnectionFailure(Exception):
|
||||
|
||||
|
||||
class ConnectionError(base.ClientException):
|
||||
"""Cannot connect to API service."""
|
||||
pass
|
||||
message = "Cannot connect to API service."
|
||||
|
||||
|
||||
class ConnectTimeout(ConnectionError, RetriableConnectionFailure):
|
||||
"""Timed out connecting to service"""
|
||||
pass
|
||||
message = "Timed out connecting to service"
|
||||
|
||||
|
||||
class ConnectFailure(ConnectionError, RetriableConnectionFailure):
|
||||
"""A retryable connection failure."""
|
||||
pass
|
||||
message = "A retryable connection failure."
|
||||
|
||||
|
||||
class SSLError(ConnectionError):
|
||||
"""An SSL error occurred."""
|
||||
pass
|
||||
message = "An SSL error occurred."
|
||||
|
||||
|
||||
class UnknownConnectionError(ConnectionError):
|
||||
|
@ -18,8 +18,8 @@ __all__ = ['DiscoveryFailure',
|
||||
|
||||
|
||||
class DiscoveryFailure(base.ClientException):
|
||||
"""Discovery of client versions failed."""
|
||||
message = "Discovery of client versions failed."
|
||||
|
||||
|
||||
class VersionNotAvailable(DiscoveryFailure):
|
||||
"""Discovery failed as the version you requested is not available."""
|
||||
message = "Discovery failed as the version you requested is not available."
|
||||
|
@ -18,7 +18,7 @@ __all__ = ['InvalidResponse']
|
||||
|
||||
|
||||
class InvalidResponse(base.ClientException):
|
||||
"""The response from the server is not valid for this request."""
|
||||
message = "The response from the server is not valid for this request."
|
||||
|
||||
def __init__(self, response):
|
||||
super(InvalidResponse, self).__init__()
|
||||
|
Loading…
Reference in New Issue
Block a user