feat: Retorno errores VIAEXPRESS refs #6682
gitea/salix/pipeline/pr-dev There was a failure building this commit Details

This commit is contained in:
Carlos Andrés 2024-04-18 17:27:18 +02:00
parent 08ca1a302b
commit 70f3b9292a
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);
};
};