-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expanded exceptions gcloud and its storage sub-module.
- Loading branch information
Kevin Leyow
authored and
Kevin Leyow
committed
Sep 22, 2014
1 parent
1f2aaf3
commit 4362994
Showing
2 changed files
with
73 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# TODO: Make these super useful. | ||
import ast | ||
|
||
class Error(Exception): | ||
""" | ||
General Gcloud error. | ||
""" | ||
def __init__(self, message, *args): | ||
super(GcloudClientError, self).__init__(message, *args) | ||
self.message = message | ||
|
||
def __repr__(self): | ||
return 'GcloudClientError: %s' % self.message | ||
|
||
def __str__(self): | ||
return 'GcloudClientError: %s' % self.message | ||
|
||
|
||
class ConnectionError(Exception): | ||
""" | ||
General error handler for HTTP errors for gclouds sub-modules. | ||
""" | ||
def __init__(self, response, content, *args): | ||
super(ConnectionError, self).__init__(response, content, *args) | ||
evaluated_content = ast.literal_eval(content) | ||
self.headers = response | ||
self.status = response.status | ||
self.date = response['date'] | ||
self.expires = response['expires'] | ||
self.errors = evaluated_content["error"]["errors"] | ||
self.message = evaluated_content["error"]["message"] | ||
|
||
|
||
def __repr__(self): | ||
return '%s: Status: %s Message: %s' % (self.__class__.__name__, | ||
self.status, self.message) | ||
|
||
def __str__(self): | ||
return '%s: Status: %s Message: %s' % (self.__class__.__name__, | ||
self.status, self.message) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,45 @@ | ||
# TODO: Make these super useful. | ||
from gcloud import exceptions | ||
|
||
class StorageError(Exception): | ||
|
||
class ConnectionError(exceptions.ConnectionError): | ||
""" | ||
Storage error handler for HTTP response errors for gcloud storage. | ||
""" | ||
pass | ||
|
||
|
||
class ConnectionError(StorageError): | ||
class NotFoundError(ConnectionError): | ||
pass | ||
|
||
|
||
def __init__(self, response, content): | ||
message = str(response) + content | ||
super(ConnectionError, self).__init__(message) | ||
class UnauthorizedError(ConnectionError): | ||
pass | ||
|
||
|
||
class NotFoundError(ConnectionError): | ||
class InvalidBucketNameError(ConnectionError): | ||
pass | ||
|
||
|
||
class TooManyBucketsError(ConnectionError): | ||
pass | ||
|
||
|
||
def __init__(self, response, content): | ||
self.message = 'Request returned a 404. Headers: %s' % (response) | ||
class BucketAlreadyExistsError(ConnectionError): | ||
pass | ||
|
||
|
||
class DomainVerificationRequiredError(ConnectionError): | ||
pass | ||
|
||
|
||
class BucketAlreadyOwnedByYouError(ConnectionError): | ||
pass | ||
|
||
|
||
class BucketNameUnavailableError(ConnectionError): | ||
pass | ||
|
||
|
||
class StorageDataError(StorageError): | ||
class KeyTooLongError(ConnectionError): | ||
pass |