@@ -195,39 +195,43 @@ def _handle_response(self, response):
195
195
196
196
@staticmethod
197
197
def _handle_error (response ):
198
+
199
+ exception_type = WLSException
200
+ exception_message = 'An unknown error occured.'
201
+
198
202
if response .status_code == 400 :
199
- raise BadRequestException ( response . json ()[ 'detail' ])
203
+ exception_type = BadRequestException
200
204
201
205
if response .status_code == 401 :
202
206
# does not return json
203
207
raise UnauthorizedException ()
204
208
205
209
if response .status_code == 403 :
206
- raise ForbiddenException ( response . json ()[ 'detail' ])
210
+ exception_type = ForbiddenException
207
211
208
212
if response .status_code == 404 :
209
- raise NotFoundException ( response . json ()[ 'detail' ])
213
+ exception_type = NotFoundException
210
214
211
215
if response .status_code == 405 :
212
- raise MethodNotAllowedException ( response . json ()[ 'detail' ])
216
+ exception_type = MethodNotAllowedException
213
217
214
218
if response .status_code == 406 :
215
- raise NotAcceptableException ( response . json ()[ 'detail' ])
219
+ exception_type = NotAcceptableException
216
220
217
221
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
224
223
225
224
if response .status_code == 503 :
226
- raise ServiceUnavailableException ( response . json ()[ 'detail' ])
225
+ exception_type = ServiceUnavailableException
227
226
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 )
231
235
232
236
233
237
class WLSObject (object ):
0 commit comments