summaryrefslogtreecommitdiff
path: root/gitlab.py
diff options
context:
space:
mode:
authorMika Mäenpää <mika.j.maenpaa@tut.fi>2014-11-01 15:21:49 +0200
committerMika Mäenpää <mika.j.maenpaa@tut.fi>2014-11-01 15:56:43 +0200
commit8351b2d5fcb66fa7b0a6fae6e88aa5ad81126a42 (patch)
tree2da5fa0e9e01d36d61bc02790bc79aaae5f50f55 /gitlab.py
parent555cc45638f18bf74099fb8c8d6dca46a64fea73 (diff)
downloadgitlab-8351b2d5fcb66fa7b0a6fae6e88aa5ad81126a42.tar.gz
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.
Diffstat (limited to 'gitlab.py')
-rw-r--r--gitlab.py41
1 files changed, 32 insertions, 9 deletions
diff --git a/gitlab.py b/gitlab.py
index 8034529..6dfa1cd 100644
--- a/gitlab.py
+++ b/gitlab.py
@@ -42,39 +42,62 @@ class jsonEncoder(json.JSONEncoder):
return json.JSONEncoder.default(self, obj)
-class GitlabConnectionError(Exception):
+class GitlabError(Exception):
+ def __init__(self, error_message="", response_code=None,
+ response_body=None):
+
+ Exception.__init__(self, error_message)
+ # Http status code
+ self.response_code = response_code
+ # Full http response
+ self.response_body = response_body
+ # Parsed error message from gitlab
+ self.error_message = error_message
+
+ def __str__(self):
+ if self.response_code is not None:
+ return "{0}: {1}".format(self.response_code, self.error_message)
+ else:
+ return "{0}".format(self.error_message)
+
+
+class GitlabAuthenticationError(GitlabError):
+ pass
+
+
+class GitlabConnectionError(GitlabError):
pass
-class GitlabListError(Exception):
+class GitlabOperationError(GitlabError):
pass
-class GitlabGetError(Exception):
+class GitlabListError(GitlabOperationError):
pass
-class GitlabCreateError(Exception):
+class GitlabGetError(GitlabOperationError):
pass
-class GitlabUpdateError(Exception):
+class GitlabCreateError(GitlabOperationError):
pass
-class GitlabDeleteError(Exception):
+class GitlabUpdateError(GitlabOperationError):
pass
-class GitlabProtectError(Exception):
+class GitlabDeleteError(GitlabOperationError):
pass
-class GitlabTransferProjectError(Exception):
+class GitlabProtectError(GitlabOperationError):
pass
-class GitlabAuthenticationError(Exception):
+class GitlabTransferProjectError(GitlabOperationError):
pass