@@ -213,26 +213,34 @@ def _combine_url(part1, part2):
213213 return part1 .rstrip ('/' ) + '/' + part2 .strip ('/' )
214214
215215 def _handle_error (self , request , response ):
216- try :
217- wrapped_exception = self ._base_deserialize ('WrappedException' , response )
218- if wrapped_exception is not None and wrapped_exception .message is not None :
219- raise VstsServiceError (wrapped_exception )
220- else :
221- # System exceptions from controllers are not returning wrapped exceptions.
222- # Following code is to handle this unusual exception json case.
223- # TODO: dig into this.
224- collection_wrapper = self ._base_deserialize ('VssJsonCollectionWrapper' , response )
225- if collection_wrapper is not None :
226- wrapped_exception = self ._base_deserialize ('ImproperException' , collection_wrapper .value )
227- raise VstsClientRequestError (wrapped_exception .message )
228- except DeserializationError :
229- pass
216+ print (response .headers )
217+ content_type = response .headers .get ('Content-Type' )
218+ error_message = ''
219+ if content_type is None or content_type .find ('text/plain' ) < 0 :
220+ try :
221+ wrapped_exception = self ._base_deserialize ('WrappedException' , response )
222+ if wrapped_exception is not None and wrapped_exception .message is not None :
223+ raise VstsServiceError (wrapped_exception )
224+ else :
225+ # System exceptions from controllers are not returning wrapped exceptions.
226+ # Following code is to handle this unusual exception json case.
227+ # TODO: dig into this.
228+ collection_wrapper = self ._base_deserialize ('VssJsonCollectionWrapper' , response )
229+ if collection_wrapper is not None :
230+ wrapped_exception = self ._base_deserialize ('ImproperException' , collection_wrapper .value )
231+ raise VstsClientRequestError (wrapped_exception .message )
232+ except DeserializationError :
233+ pass
234+ elif response .content is not None :
235+ error_message = response .content .decode ("utf-8" ) + ' '
230236 if response .status_code == 401 :
231- raise VstsAuthenticationError ('The requested resource requires user authentication: ' +
232- request .url )
237+ full_message_format = '{error_message}The requested resource requires user authentication: {url}'
238+ raise VstsAuthenticationError (full_message_format .format (error_message = error_message ,
239+ url = request .url ))
233240 else :
234- raise VstsClientRequestError ('"Operation returned an invalid status code of {status_code}.'
235- .format (status_code = response .status_code ))
241+ full_message_format = '{error_message}Operation returned an invalid status code of {status_code}.'
242+ raise VstsClientRequestError (full_message_format .format (error_message = error_message ,
243+ status_code = response .status_code ))
236244
237245 @staticmethod
238246 def _normalize_url (url ):
0 commit comments