feat: Retorno errores VIAEXPRESS refs #6682 #2330
|
@ -20,14 +20,14 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.internationalExpedition = async (expeditionFk) => {
|
Self.internationalExpedition = async expeditionFk => {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
|
|
||||||
const viaexpressConfig = await models.ViaexpressConfig.findOne({
|
const viaexpressConfig = await models.ViaexpressConfig.findOne({
|
||||||
fields: ['url']
|
fields: ['url']
|
||||||
});
|
});
|
||||||
|
|
||||||
const renderedXml = await models.ViaexpressConfig.renderer(expeditionFk);
|
const renderedXml = await models.ViaexpressConfig.renderer(expeditionFk);
|
||||||
|
|
||||||
const response = await axios.post(`${viaexpressConfig.url}ServicioVxClientes.asmx`, renderedXml, {
|
const response = await axios.post(`${viaexpressConfig.url}ServicioVxClientes.asmx`, renderedXml, {
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/soap+xml; charset=utf-8'
|
'Content-Type': 'application/soap+xml; charset=utf-8'
|
||||||
|
@ -37,9 +37,12 @@ module.exports = Self => {
|
||||||
const xmlString = response.data;
|
const xmlString = response.data;
|
||||||
const parser = new DOMParser();
|
const parser = new DOMParser();
|
||||||
const xmlDoc = parser.parseFromString(xmlString, 'text/xml');
|
const xmlDoc = parser.parseFromString(xmlString, 'text/xml');
|
||||||
const referenciaVxElement = xmlDoc.getElementsByTagName('ReferenciaVx')[0];
|
const {textContent} = xmlDoc.getElementsByTagName('Resultado')[0];
|
||||||
const referenciaVx = referenciaVxElement.textContent;
|
|
||||||
|
|
||||||
return referenciaVx;
|
if (textContent === 'OK')
|
||||||
|
return xmlDoc.getElementsByTagName('ReferenciaVx')[0].textContent;
|
||||||
|
|
||||||
|
const message = xmlDoc.getElementsByTagName('Mensaje')[0];
|
||||||
|
throw new Error(textContent + ': ' + message.textContent);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue