diff options
| author | Mika Mäenpää <mika.j.maenpaa@tut.fi> | 2014-11-01 15:21:49 +0200 |
|---|---|---|
| committer | Mika Mäenpää <mika.j.maenpaa@tut.fi> | 2014-11-01 15:56:43 +0200 |
| commit | 8351b2d5fcb66fa7b0a6fae6e88aa5ad81126a42 (patch) | |
| tree | 2da5fa0e9e01d36d61bc02790bc79aaae5f50f55 /gitlab.py | |
| parent | 555cc45638f18bf74099fb8c8d6dca46a64fea73 (diff) | |
| download | gitlab-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.py | 41 |
1 files changed, 32 insertions, 9 deletions
@@ -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 |
