LIBCLOUD-331: Adds the new error type ProviderError. Modifies InvalidCredsError to extend from it.
Signed-off-by: Tomaz Muraus <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/30dfdb48 Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/30dfdb48 Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/30dfdb48 Branch: refs/heads/0.12.x Commit: 30dfdb4848cf7c0cfb42c331afd657b01fbf2be1 Parents: 5c7b98d Author: Jayy Vis <[email protected]> Authored: Wed Jun 26 02:47:24 2013 +0530 Committer: Tomaz Muraus <[email protected]> Committed: Tue Jun 25 23:48:06 2013 +0200 ---------------------------------------------------------------------- libcloud/common/types.py | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/30dfdb48/libcloud/common/types.py ---------------------------------------------------------------------- diff --git a/libcloud/common/types.py b/libcloud/common/types.py index 2c31575..f6b9494 100644 --- a/libcloud/common/types.py +++ b/libcloud/common/types.py @@ -13,13 +13,16 @@ # See the License for the specific language governing permissions and # limitations under the License. +from libcloud.utils.py3 import httplib + __all__ = [ "LibcloudError", "MalformedResponseError", + "ProviderError", "InvalidCredsError", "InvalidCredsException", "LazyList" - ] +] class LibcloudError(Exception): @@ -61,12 +64,20 @@ class MalformedResponseError(LibcloudError): + repr(self.body)) -class InvalidCredsError(LibcloudError): - """Exception used when invalid credentials are used on a provider.""" +class ProviderError(LibcloudError): + """ + Exception used when provider gives back + error response (HTTP 4xx, 5xx) for a request. - def __init__(self, value='Invalid credentials with the provider', + Specific sub types can be derieved for errors like + HTTP 401 : InvalidCredsError + HTTP 404 : NodeNotFoundError, ContainerDoesNotExistError + """ + + def __init__(self, value, http_code, driver=None): self.value = value + self.http_code = http_code self.driver = driver def __str__(self): @@ -76,6 +87,16 @@ class InvalidCredsError(LibcloudError): return repr(self.value) +class InvalidCredsError(ProviderError): + """Exception used when invalid credentials are used on a provider.""" + + def __init__(self, value='Invalid credentials with the provider', + driver=None): + super(InvalidCredsError, self).__init__(value, + http_code=httplib.UNAUTHORIZED, + driver=driver) + + # Deprecated alias of L{InvalidCredsError} InvalidCredsException = InvalidCredsError
