def parse_request_response(self, reqresp, response, body_type, state="", **kwargs): if reqresp.status_code in SUCCESSFUL: body_type = verify_header(reqresp, body_type) elif reqresp.status_code == 302: # redirect pass elif reqresp.status_code == 500: logger.error("(%d) %s" % (reqresp.status_code, reqresp.text)) raise ParseError("ERROR: Something went wrong: %s" % reqresp.text) elif reqresp.status_code in [400, 401]: #expecting an error response if issubclass(response, ErrorResponse): pass else: logger.error("(%d) %s" % (reqresp.status_code, reqresp.text)) raise HttpError("HTTP ERROR: %s [%s] on %s" % (reqresp.text, reqresp.status_code, reqresp.url)) if body_type: if response: return self.parse_response(response, reqresp.text, body_type, state, **kwargs) else: raise OtherError("Didn't expect a response body") else: return reqresp
def parse_request_response(self, reqresp, response, body_type, state="", verify=True, **kwargs): if reqresp.status_code in SUCCESSFUL: body_type = verify_header(reqresp, body_type) elif reqresp.status_code in [302, 303]: # redirect return reqresp elif reqresp.status_code == 500: logger.error("(%d) %s" % (reqresp.status_code, sanitize(reqresp.text))) raise ParseError("ERROR: Something went wrong: %s" % reqresp.text) elif reqresp.status_code in [400, 401]: # expecting an error response if issubclass(response, ErrorResponse): pass else: logger.error("(%d) %s" % (reqresp.status_code, sanitize(reqresp.text))) raise HttpError("HTTP ERROR: %s [%s] on %s" % (reqresp.text, reqresp.status_code, reqresp.url)) if response: if body_type == 'txt': # no meaning trying to parse unstructured text return reqresp.text if not verify: # AymRod: skip parsing return reqresp.text else: return self.parse_response(response, reqresp.text, body_type, state, **kwargs) # could be an error response if reqresp.status_code in [200, 400, 401]: if body_type == 'txt': body_type = 'urlencoded' try: err = ErrorResponse().deserialize(reqresp.message, method=body_type) try: err.verify() except PyoidcError: pass else: return err except Exception: pass return reqresp