From 70f3b9292a69cd404b097994e1867075248b81bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Thu, 18 Apr 2024 17:27:18 +0200 Subject: [PATCH] feat: Retorno errores VIAEXPRESS refs #6682 --- .../viaexpress-config/internationalExpedition.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/back/methods/viaexpress-config/internationalExpedition.js b/back/methods/viaexpress-config/internationalExpedition.js index df50b21e5..be0516050 100644 --- a/back/methods/viaexpress-config/internationalExpedition.js +++ b/back/methods/viaexpress-config/internationalExpedition.js @@ -20,14 +20,14 @@ module.exports = Self => { } }); - Self.internationalExpedition = async (expeditionFk) => { + Self.internationalExpedition = async expeditionFk => { const models = Self.app.models; const viaexpressConfig = await models.ViaexpressConfig.findOne({ fields: ['url'] }); - const renderedXml = await models.ViaexpressConfig.renderer(expeditionFk); + const response = await axios.post(`${viaexpressConfig.url}ServicioVxClientes.asmx`, renderedXml, { headers: { 'Content-Type': 'application/soap+xml; charset=utf-8' @@ -37,9 +37,12 @@ module.exports = Self => { const xmlString = response.data; const parser = new DOMParser(); const xmlDoc = parser.parseFromString(xmlString, 'text/xml'); - const referenciaVxElement = xmlDoc.getElementsByTagName('ReferenciaVx')[0]; - const referenciaVx = referenciaVxElement.textContent; + const {textContent} = xmlDoc.getElementsByTagName('Resultado')[0]; - return referenciaVx; + if (textContent === 'OK') + return xmlDoc.getElementsByTagName('ReferenciaVx')[0].textContent; + + const message = xmlDoc.getElementsByTagName('Mensaje')[0]; + throw new Error(textContent + ': ' + message.textContent); }; }; -- 2.40.1