@@ -654,6 +654,10 @@ def http_request(self, verb, path, query_data={}, post_data={},
654654 if 200 <= result .status_code < 300 :
655655 return result
656656
657+ if result .status_code == 401 :
658+ raise GitlabAuthenticationError (response_code = result .status_code ,
659+ error_message = result .content )
660+
657661 raise GitlabHttpError (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- return result .json ()
742+ if result .headers .get ('Content-Type' , None ) == 'application/json' :
743+ return result .json ()
739744 except Exception :
740745 raise GitlabParsingError (
741746 error_message = "Failed to parse the server message" )
747+ return result
742748
743749 def http_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 )
0 commit comments