Skip to content

Commit 8351b2d

Browse files
committed
Improved exception-classes.
- Added http status-code and gitlab error message to GitlabError-class. - Added new GitlabOperationError-class to help separate connection and authentication errors from other gitlab errors.
1 parent 555cc45 commit 8351b2d

File tree

1 file changed

+32
-9
lines changed

1 file changed

+32
-9
lines changed

gitlab.py

+32-9
Original file line numberDiff line numberDiff line change
@@ -42,39 +42,62 @@ def default(self, obj):
4242
return json.JSONEncoder.default(self, obj)
4343

4444

45-
class GitlabConnectionError(Exception):
45+
class GitlabError(Exception):
46+
def __init__(self, error_message="", response_code=None,
47+
response_body=None):
48+
49+
Exception.__init__(self, error_message)
50+
# Http status code
51+
self.response_code = response_code
52+
# Full http response
53+
self.response_body = response_body
54+
# Parsed error message from gitlab
55+
self.error_message = error_message
56+
57+
def __str__(self):
58+
if self.response_code is not None:
59+
return "{0}: {1}".format(self.response_code, self.error_message)
60+
else:
61+
return "{0}".format(self.error_message)
62+
63+
64+
class GitlabAuthenticationError(GitlabError):
65+
pass
66+
67+
68+
class GitlabConnectionError(GitlabError):
4669
pass
4770

4871

49-
class GitlabListError(Exception):
72+
class GitlabOperationError(GitlabError):
5073
pass
5174

5275

53-
class GitlabGetError(Exception):
76+
class GitlabListError(GitlabOperationError):
5477
pass
5578

5679

57-
class GitlabCreateError(Exception):
80+
class GitlabGetError(GitlabOperationError):
5881
pass
5982

6083

61-
class GitlabUpdateError(Exception):
84+
class GitlabCreateError(GitlabOperationError):
6285
pass
6386

6487

65-
class GitlabDeleteError(Exception):
88+
class GitlabUpdateError(GitlabOperationError):
6689
pass
6790

6891

69-
class GitlabProtectError(Exception):
92+
class GitlabDeleteError(GitlabOperationError):
7093
pass
7194

7295

73-
class GitlabTransferProjectError(Exception):
96+
class GitlabProtectError(GitlabOperationError):
7497
pass
7598

7699

77-
class GitlabAuthenticationError(Exception):
100+
class GitlabTransferProjectError(GitlabOperationError):
78101
pass
79102

80103

0 commit comments

Comments
 (0)