Skip to content

Commit 8384a48

Browse files
Kevin LeyowKevin Leyow
authored andcommitted
Expanded exceptions gcloud and its storage sub-module.
1 parent 1f2aaf3 commit 8384a48

2 files changed

Lines changed: 72 additions & 9 deletions

File tree

gcloud/exceptions.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# TODO: Make these super useful.
2+
import ast
3+
4+
class Error(Exception):
5+
"""General Gcloud error."""
6+
def __init__(self, message, *args):
7+
super(GcloudClientError, self).__init__(message, *args)
8+
self.message = message
9+
10+
def __repr__(self):
11+
return 'GcloudClientError: %s' % self.message
12+
13+
def __str__(self):
14+
return 'GcloudClientError: %s' % self.message
15+
16+
17+
class ConnectionError(Exception):
18+
"""General error handler for HTTP errors for gclouds sub-modules."""
19+
def __init__(self, response, content, *args):
20+
super(ConnectionError, self).__init__(response, content, *args)
21+
evaluated_content = ast.literal_eval(content)
22+
self.headers = response
23+
self.status = response.status
24+
self.date = response['date']
25+
self.expires = response['expires']
26+
self.errors = evaluated_content["error"]["errors"]
27+
self.message = evaluated_content["error"]["message"]
28+
29+
30+
def __repr__(self):
31+
return '%s: Status: %s Message: %s' % (self.__class__.__name__,
32+
self.status, self.message)
33+
34+
def __str__(self):
35+
return '%s: Status: %s Message: %s' % (self.__class__.__name__,
36+
self.status, self.message)

gcloud/storage/exceptions.py

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,48 @@
11
# TODO: Make these super useful.
2+
from gcloud import exceptions
23

3-
class StorageError(Exception):
4+
class StorageError(exceptions.Error):
45
pass
56

67

7-
class ConnectionError(StorageError):
8-
9-
def __init__(self, response, content):
10-
message = str(response) + content
11-
super(ConnectionError, self).__init__(message)
8+
class ConnectionError(exceptions.ConnectionError):
9+
"""
10+
Storage error handler for HTTP response errors for gcloud storage.
11+
"""
12+
pass
1213

1314

1415
class NotFoundError(ConnectionError):
16+
pass
17+
18+
19+
class UnauthorizedError(ConnectionError):
20+
pass
21+
22+
23+
class InvalidBucketNameError(ConnectionError):
24+
pass
25+
26+
27+
class TooManyBucketsError(ConnectionError):
28+
pass
1529

16-
def __init__(self, response, content):
17-
self.message = 'Request returned a 404. Headers: %s' % (response)
30+
31+
class BucketAlreadyExistsError(ConnectionError):
32+
pass
33+
34+
35+
class DomainVerificationRequiredError(ConnectionError):
36+
pass
37+
38+
39+
class BucketAlreadyOwnedByYouError(ConnectionError):
40+
pass
41+
42+
43+
class BucketNameUnavailableError(ConnectionError):
44+
pass
1845

1946

20-
class StorageDataError(StorageError):
47+
class KeyTooLongError(ConnectionError):
2148
pass

0 commit comments

Comments
 (0)