Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expanded exceptions gcloud and its storage sub-module. #177

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions gcloud/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# TODO: Make these super useful.

This comment was marked as spam.

import ast

class Error(Exception):
"""General Gcloud error."""

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

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)
45 changes: 36 additions & 9 deletions gcloud/storage/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,48 @@
# TODO: Make these super useful.
from gcloud import exceptions

class StorageError(Exception):
class StorageError(exceptions.Error):
pass


class ConnectionError(StorageError):

def __init__(self, response, content):
message = str(response) + content
super(ConnectionError, self).__init__(message)
class ConnectionError(exceptions.ConnectionError):
"""
Storage error handler for HTTP response errors for gcloud storage.
"""
pass


class NotFoundError(ConnectionError):
pass


class UnauthorizedError(ConnectionError):
pass


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