@@ -354,26 +354,29 @@ def _loads(self, xmldata, decode=True, origxml=None):
354
354
return self ._postamble ()
355
355
356
356
def status_ok (self ):
357
- if self .response .status :
358
- status = self .response .status
359
- logger .info ("status: %s" , status )
360
- if status .status_code .value != samlp .STATUS_SUCCESS :
361
- logger .info ("Not successful operation: %s" , status )
362
- if status .status_code .status_code :
363
- excep = STATUSCODE2EXCEPTION .get (
364
- status .status_code .status_code .value , StatusError )
365
- else :
366
- excep = StatusError
367
- if status .status_message :
368
- msg = status .status_message .text
369
- else :
370
- try :
371
- msg = status .status_code .status_code .value
372
- except Exception :
373
- msg = "Unknown error"
374
- raise excep (
375
- "%s from %s" % (msg , status .status_code .value ,))
376
- return True
357
+ status = self .response .status
358
+ logger .info ("status: %s" , status )
359
+
360
+ if not status or status .status_code .value == samlp .STATUS_SUCCESS :
361
+ return True
362
+
363
+ err_code = (
364
+ status .status_code .status_code .value
365
+ if status .status_code .status_code
366
+ else None
367
+ )
368
+ err_msg = (
369
+ status .status_message .text
370
+ if status .status_message
371
+ else err_code or "Unknown error"
372
+ )
373
+ err_cls = STATUSCODE2EXCEPTION .get (err_code , StatusError )
374
+
375
+ msg = "Unsuccessful operation: {status}\n {msg} from {code}" .format (
376
+ status = status , msg = err_msg , code = err_code
377
+ )
378
+ logger .info (msg )
379
+ raise err_cls (msg )
377
380
378
381
def issue_instant_ok (self ):
379
382
""" Check that the response was issued at a reasonable time """
0 commit comments