diff options
| author | Gauvain Pocentek <gauvain@pocentek.net> | 2017-07-15 17:05:44 +0200 |
|---|---|---|
| committer | Gauvain Pocentek <gauvain@pocentek.net> | 2017-07-15 17:05:44 +0200 |
| commit | c15ba3b61065973da983ff792a34268a3ba75e12 (patch) | |
| tree | a4de60e66c14a4f1179c92be821d2602a766b6b1 /gitlab/__init__.py | |
| parent | 374a6c4544931a564221cccabb6abbda9e6bc558 (diff) | |
| download | gitlab-c15ba3b61065973da983ff792a34268a3ba75e12.tar.gz | |
Restore correct exceptions
Match the exceptions raised in v3 for v4.
Also update the doc strings with correct information.
Diffstat (limited to 'gitlab/__init__.py')
| -rw-r--r-- | gitlab/__init__.py | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/gitlab/__init__.py b/gitlab/__init__.py index 0696f34..6a55fee 100644 --- a/gitlab/__init__.py +++ b/gitlab/__init__.py @@ -654,6 +654,10 @@ class Gitlab(object): if 200 <= result.status_code < 300: return result + if result.status_code == 401: + raise GitlabAuthenticationError(response_code=result.status_code, + error_message=result.content) + raise GitlabHttpError(response_code=result.status_code, error_message=result.content) @@ -674,7 +678,7 @@ class Gitlab(object): Raises: GitlabHttpError: When the return code is not 2xx - GitlabParsingError: IF the json data could not be parsed + GitlabParsingError: If the json data could not be parsed """ result = self.http_request('get', path, query_data=query_data, streamed=streamed, **kwargs) @@ -706,7 +710,7 @@ class Gitlab(object): Raises: GitlabHttpError: When the return code is not 2xx - GitlabParsingError: IF the json data could not be parsed + GitlabParsingError: If the json data could not be parsed """ url = self._build_url(path) get_all = kwargs.pop('all', False) @@ -726,19 +730,21 @@ class Gitlab(object): Returns: The parsed json returned by the server if json is return, else the - raw content. + raw content Raises: GitlabHttpError: When the return code is not 2xx - GitlabParsingError: IF the json data could not be parsed + GitlabParsingError: If the json data could not be parsed """ result = self.http_request('post', path, query_data=query_data, post_data=post_data, **kwargs) try: - return result.json() + if result.headers.get('Content-Type', None) == 'application/json': + return result.json() except Exception: raise GitlabParsingError( error_message="Failed to parse the server message") + return result def http_put(self, path, query_data={}, post_data={}, **kwargs): """Make a PUT request to the Gitlab server. @@ -756,7 +762,7 @@ class Gitlab(object): Raises: GitlabHttpError: When the return code is not 2xx - GitlabParsingError: IF the json data could not be parsed + GitlabParsingError: If the json data could not be parsed """ result = self.http_request('put', path, query_data=query_data, post_data=post_data, **kwargs) |
