Updated Branches:
  refs/heads/0.12.x 5c7b98d31 -> ed8350e03
  refs/heads/trunk 33d4f48eb -> fb11854c6


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/cb9d3747
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/cb9d3747
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/cb9d3747

Branch: refs/heads/trunk
Commit: cb9d374732fca01d488e117221baf1fbf6603032
Parents: 33d4f48
Author: Jayy Vis <[email protected]>
Authored: Wed Jun 26 02:47:24 2013 +0530
Committer: Tomaz Muraus <[email protected]>
Committed: Tue Jun 25 23:38:27 2013 +0200

----------------------------------------------------------------------
 libcloud/common/types.py | 29 +++++++++++++++++++++++++----
 1 file changed, 25 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/cb9d3747/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
 

Reply via email to