@@ -195,39 +195,43 @@ def _handle_response(self, response):
195195
196196 @staticmethod
197197 def _handle_error (response ):
198+
199+ exception_type = WLSException
200+ exception_message = 'An unknown error occured.'
201+
198202 if response .status_code == 400 :
199- raise BadRequestException ( response . json ()[ 'detail' ])
203+ exception_type = BadRequestException
200204
201205 if response .status_code == 401 :
202206 # does not return json
203207 raise UnauthorizedException ()
204208
205209 if response .status_code == 403 :
206- raise ForbiddenException ( response . json ()[ 'detail' ])
210+ exception_type = ForbiddenException
207211
208212 if response .status_code == 404 :
209- raise NotFoundException ( response . json ()[ 'detail' ])
213+ exception_type = NotFoundException
210214
211215 if response .status_code == 405 :
212- raise MethodNotAllowedException ( response . json ()[ 'detail' ])
216+ exception_type = MethodNotAllowedException
213217
214218 if response .status_code == 406 :
215- raise NotAcceptableException ( response . json ()[ 'detail' ])
219+ exception_type = NotAcceptableException
216220
217221 if response .status_code == 500 :
218- # may not return json...
219- try :
220- raise ServerErrorException (response .json ()['detail' ])
221- except ValueError :
222- pass
223- raise ServerErrorException (response .text )
222+ exception_type = ServerErrorException
224223
225224 if response .status_code == 503 :
226- raise ServiceUnavailableException ( response . json ()[ 'detail' ])
225+ exception_type = ServiceUnavailableException
227226
228- raise WLSException (
229- 'An unknown error occured. Got status code: {}' .format (response .status_code )
230- )
227+ try :
228+ exception_message = response .json ()['detail' ]
229+ except KeyError :
230+ exception_message = response .json ()
231+ except ValueError :
232+ exception_message = response .text
233+
234+ raise exception_type (exception_message )
231235
232236
233237class WLSObject (object ):
0 commit comments