summaryrefslogtreecommitdiff
path: root/gitlab/exceptions.py
diff options
context:
space:
mode:
authorGauvain Pocentek <gauvain@pocentek.net>2016-03-22 17:59:53 +0100
committerGauvain Pocentek <gauvain@pocentek.net>2016-03-22 17:59:53 +0100
commit43e8a2a82deff4c95e156fc951f88ff6e95cf7b8 (patch)
treee121aaa940d8c03a84f266a967173748b7bb1bf4 /gitlab/exceptions.py
parentbb463ae4e0ed79e472c0d594f76dc8177a29fb5c (diff)
downloadgitlab-43e8a2a82deff4c95e156fc951f88ff6e95cf7b8.tar.gz
Add support for MergeRequest validation
Both API and CLI support this feature. fixes #105
Diffstat (limited to 'gitlab/exceptions.py')
-rw-r--r--gitlab/exceptions.py22
1 files changed, 19 insertions, 3 deletions
diff --git a/gitlab/exceptions.py b/gitlab/exceptions.py
index 1b5ec6a..ce1f680 100644
--- a/gitlab/exceptions.py
+++ b/gitlab/exceptions.py
@@ -91,6 +91,18 @@ class GitlabUnblockError(GitlabOperationError):
pass
+class GitlabMRForbiddenError(GitlabOperationError):
+ pass
+
+
+class GitlabMRClosedError(GitlabOperationError):
+ pass
+
+
+class GitlabMROnBuildSuccessError(GitlabOperationError):
+ pass
+
+
def raise_error_from_response(response, error, expected_code=200):
"""Tries to parse gitlab error message from response and raises error.
@@ -99,7 +111,8 @@ def raise_error_from_response(response, error, expected_code=200):
If response status code is 401, raises instead GitlabAuthenticationError.
response: requests response object
- error: Error-class to raise. Should be inherited from GitLabError
+ error: Error-class or dict {return-code => class} of possible error class
+ to raise. Should be inherited from GitLabError
"""
if expected_code == response.status_code:
@@ -110,8 +123,11 @@ def raise_error_from_response(response, error, expected_code=200):
except (KeyError, ValueError):
message = response.content
- if response.status_code == 401:
- error = GitlabAuthenticationError
+ if isinstance(error, dict):
+ error = error.get(response.status_code, GitlabOperationError)
+ else:
+ if response.status_code == 401:
+ error = GitlabAuthenticationError
raise error(error_message=message,
response_code=response.status_code,