def _handle_errors(self, response): """Handle reponse in case of ERROR 400 type.""" try: gls_errors = response.json()["errors"] except: errors = [] else: errors = [{ "id": e.get("exitCode") or "unkown_%d" % response.status_code, "message": self._better_error_message( e.get("description") or e.get("exitMessage") or response.reason, e.get("exitCode"), ), } for e in gls_errors] if not errors: errors.append({ "id": "unspecified_%d" % response.status_code, "message": self._better_error_message(response.reason), }) raise CarrierError(response, errors)
def handle_true_negative_error(self, response, payload): """When servers answer an error with a 200 status code.""" errors = [{ "id": payload.get("codeErreur", ""), "message": payload.get("texteErreur", ""), }] raise CarrierError(response, errors)
def handle_500(self, response): """Handle reponse in case of ERROR 500 type.""" # TODO : put a try catch (like wrong server) log.warning("Geodis error 500") errors = [{ "id": "", "message": "", }] raise CarrierError(response, errors)
def handle_500(self, response): """Handle reponse in case of ERROR 500 type.""" log.warning('Dpd error 500') obj = objectify.fromstring(response.content) errors = [{ "id": obj.xpath('//faultcode')[0], "message": obj.xpath('//faultstring')[0], }] raise CarrierError(response, errors)
def raise_on_error(response_xml): xml = objectify.fromstring(response_xml) messages = xml.xpath('//messages') errors = [{ 'id': message.id, 'message': unicode(message.messageContent), } for message in messages if message.type == "ERROR"] if len(errors) > 0: raise CarrierError(response, errors)
def raise_on_error(response_xml): xml = objectify.fromstring(response_xml) messages = xml.xpath("//messages") errors = [ {"id": message.id, "message": str(message.messageContent),} for message in messages if message.type == "ERROR" ] if len(errors) > 0: raise CarrierError(response, errors)
def handle_response(self, response): """Handle response of webservice.""" if response.status_code == 500: return self.handle_500(response) elif response.status_code == 200: return self.handle_200(response) else: raise CarrierError(response, [{ 'id': None, 'message': "Unexpected status code from server", }])
def handle_500(self, response): """Handle reponse in case of ERROR 500 type.""" log.warning("Laposte error 500") obj = objectify.fromstring(response.text) errors = [ { "id": obj.xpath("//faultcode")[0], "message": obj.xpath("//faultstring")[0], } ] raise CarrierError(response, errors)
def handle_response(self, response): """Handle response of webservice.""" if response.status_code == 200: return self.handle_200(response) elif response.status_code == 500: return self.handle_500(response) # will raise else: raise CarrierError( response, [{"id": None, "message": "Unexpected status code from server"}], )
def handle_500(self, response): """Handle reponse in case of ERROR 500 type.""" log.warning("Dpd error 500") obj = objectify.fromstring(response.content) error_id = (obj.xpath("//ErrorId") or obj.xpath("//faultcode"))[0] error_message = (obj.xpath("//ErrorMessage") or obj.xpath("//faultstring"))[0] raise CarrierError(response, [{ "id": error_id, "message": error_message, }])
def handle_200(self, response): """Handle response type 200 (success).""" def extract_soap(response_xml): obj = objectify.fromstring(response_xml) return obj.Body.getchildren()[0] body = extract_soap(response.content) result = body.getchildren()[0] if result.errorCode != 0: raise CarrierError(response, result.errorMessage) body_xml = etree.tostring(body) return {"body": body_xml, "response": response}
def handle_500(self, response): """Handle reponse in case of ERROR 500 type.""" # TODO : put a try catch (like wrong server) # no need to extract_body shit here log.warning('Geodis error 500') xml = get_parts(response)['start'] obj = objectify.fromstring(xml) message = obj.xpath("//*[local-name() = 'message']") if len(message) > 0: message = message[0] or obj.xpath('//faultstring')[0] id_message = obj.xpath("//*[local-name() = 'code']")[0] errors = [{ "id": id_message, "message": message, }] raise CarrierError(response, errors)
def handle_500(self, response): """Handle reponse in case of ERROR 500 type.""" # TODO : put a try catch (like wrong server) log.warning("Geodis error 500") xml = get_parts(response)["start"] obj = objectify.fromstring(xml) message = obj.xpath("//*[local-name() = 'message']") id_message = None if len(message) > 0: message = message[0] or obj.xpath("//faultstring")[0] id_message = (obj.xpath("//*[local-name() = 'code']") and obj.xpath("//*[local-name() = 'code']")[0] or "") errors = [{ "id": id_message, "message": message, }] raise CarrierError(response, errors)
def create_exception(self, result, exception, ctx_except, data_request): exc = "%s\n\n" "Contexte :\n\t%s" % (exception, ctx_except) log.warning("Gls exception Roulier library ") log.warning(exc) log.warning("Données envoyées:\n%s" % data_request) raise CarrierError(result, exc)
def handle_500(self, response): """Handle reponse in case of ERROR 500 type.""" log.warning("Gls error 500") errors = [{}] raise CarrierError(response, errors)