Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc15ba3b

Browse files
author
Gauvain Pocentek
committed
Restore correct exceptions
Match the exceptions raised in v3 for v4.Also update the doc strings with correct information.
1 parent374a6c4 commitc15ba3b

File tree

5 files changed

+655
-148
lines changed

5 files changed

+655
-148
lines changed

‎gitlab/__init__.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,10 @@ def http_request(self, verb, path, query_data={}, post_data={},
654654
if200<=result.status_code<300:
655655
returnresult
656656

657+
ifresult.status_code==401:
658+
raiseGitlabAuthenticationError(response_code=result.status_code,
659+
error_message=result.content)
660+
657661
raiseGitlabHttpError(response_code=result.status_code,
658662
error_message=result.content)
659663

@@ -674,7 +678,7 @@ def http_get(self, path, query_data={}, streamed=False, **kwargs):
674678
675679
Raises:
676680
GitlabHttpError: When the return code is not 2xx
677-
GitlabParsingError:IF the json data could not be parsed
681+
GitlabParsingError:If the json data could not be parsed
678682
"""
679683
result=self.http_request('get',path,query_data=query_data,
680684
streamed=streamed,**kwargs)
@@ -706,7 +710,7 @@ def http_list(self, path, query_data={}, **kwargs):
706710
707711
Raises:
708712
GitlabHttpError: When the return code is not 2xx
709-
GitlabParsingError:IF the json data could not be parsed
713+
GitlabParsingError:If the json data could not be parsed
710714
"""
711715
url=self._build_url(path)
712716
get_all=kwargs.pop('all',False)
@@ -726,19 +730,21 @@ def http_post(self, path, query_data={}, post_data={}, **kwargs):
726730
727731
Returns:
728732
The parsed json returned by the server if json is return, else the
729-
raw content.
733+
raw content
730734
731735
Raises:
732736
GitlabHttpError: When the return code is not 2xx
733-
GitlabParsingError:IF the json data could not be parsed
737+
GitlabParsingError:If the json data could not be parsed
734738
"""
735739
result=self.http_request('post',path,query_data=query_data,
736740
post_data=post_data,**kwargs)
737741
try:
738-
returnresult.json()
742+
ifresult.headers.get('Content-Type',None)=='application/json':
743+
returnresult.json()
739744
exceptException:
740745
raiseGitlabParsingError(
741746
error_message="Failed to parse the server message")
747+
returnresult
742748

743749
defhttp_put(self,path,query_data={},post_data={},**kwargs):
744750
"""Make a PUT request to the Gitlab server.
@@ -756,7 +762,7 @@ def http_put(self, path, query_data={}, post_data={}, **kwargs):
756762
757763
Raises:
758764
GitlabHttpError: When the return code is not 2xx
759-
GitlabParsingError:IF the json data could not be parsed
765+
GitlabParsingError:If the json data could not be parsed
760766
"""
761767
result=self.http_request('put',path,query_data=query_data,
762768
post_data=post_data,**kwargs)

‎gitlab/exceptions.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,3 +210,23 @@ class to raise. Should be inherited from GitLabError
210210
raiseerror(error_message=message,
211211
response_code=response.status_code,
212212
response_body=response.content)
213+
214+
215+
defon_http_error(error):
216+
"""Manage GitlabHttpError exceptions.
217+
218+
This decorator function can be used to catch GitlabHttpError exceptions
219+
raise specialized exceptions instead.
220+
221+
Args:
222+
error(Exception): The exception type to raise -- must inherit from
223+
GitlabError
224+
"""
225+
defwrap(f):
226+
defwrapped_f(*args,**kwargs):
227+
try:
228+
returnf(*args,**kwargs)
229+
exceptGitlabHttpErrorase:
230+
raiseerror(e.response_code,e.error_message)
231+
returnwrapped_f
232+
returnwrap

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp