@@ -654,6 +654,10 @@ def http_request(self, verb, path, query_data={}, post_data={},
654
654
if 200 <= result .status_code < 300 :
655
655
return result
656
656
657
+ if result .status_code == 401 :
658
+ raise GitlabAuthenticationError (response_code = result .status_code ,
659
+ error_message = result .content )
660
+
657
661
raise GitlabHttpError (response_code = result .status_code ,
658
662
error_message = result .content )
659
663
@@ -674,7 +678,7 @@ def http_get(self, path, query_data={}, streamed=False, **kwargs):
674
678
675
679
Raises:
676
680
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
678
682
"""
679
683
result = self .http_request ('get' , path , query_data = query_data ,
680
684
streamed = streamed , ** kwargs )
@@ -706,7 +710,7 @@ def http_list(self, path, query_data={}, **kwargs):
706
710
707
711
Raises:
708
712
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
710
714
"""
711
715
url = self ._build_url (path )
712
716
get_all = kwargs .pop ('all' , False )
@@ -726,19 +730,21 @@ def http_post(self, path, query_data={}, post_data={}, **kwargs):
726
730
727
731
Returns:
728
732
The parsed json returned by the server if json is return, else the
729
- raw content.
733
+ raw content
730
734
731
735
Raises:
732
736
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
734
738
"""
735
739
result = self .http_request ('post' , path , query_data = query_data ,
736
740
post_data = post_data , ** kwargs )
737
741
try :
738
- return result .json ()
742
+ if result .headers .get ('Content-Type' , None ) == 'application/json' :
743
+ return result .json ()
739
744
except Exception :
740
745
raise GitlabParsingError (
741
746
error_message = "Failed to parse the server message" )
747
+ return result
742
748
743
749
def http_put (self , path , query_data = {}, post_data = {}, ** kwargs ):
744
750
"""Make a PUT request to the Gitlab server.
@@ -756,7 +762,7 @@ def http_put(self, path, query_data={}, post_data={}, **kwargs):
756
762
757
763
Raises:
758
764
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
760
766
"""
761
767
result = self .http_request ('put' , path , query_data = query_data ,
762
768
post_data = post_data , ** kwargs )
0 commit comments