feat: Retorno errores VIAEXPRESS refs #6682 #2330

Open
carlosap wants to merge 2 commits from 6682-Retorno-errores-de-VIAEXPRESS into dev
1 changed files with 8 additions and 5 deletions

View File

@ -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);
};
};