diff --git a/src/core/findUserPdl.js b/src/core/findUserPdl.js index 3c5bba7e081396975d3e13af9793b5ac93ee0332..137a8cc3416d70b63c4c9e1032e65269f06c8fbf 100644 --- a/src/core/findUserPdl.js +++ b/src/core/findUserPdl.js @@ -32,50 +32,60 @@ async function findUserPdl( apikey: apiAuthKey, } - const { response } = await soapRequest({ - url: url, - headers: sgeHeaders, - xml: rechercherPoint( - appLogin, - lastname, - postalCode, - inseeCode, - address, - escalierEtEtageEtAppartement - ), - }).catch(err => { - const errorMessage = 'Error while finding user pdl : ' + err.message - log('error', errorMessage) - Sentry.captureException(errorMessage, { + try { + const { response } = await soapRequest({ + url: url, + headers: sgeHeaders, + xml: rechercherPoint( + appLogin, + lastname, + postalCode, + inseeCode, + address, + escalierEtEtageEtAppartement + ), + }).catch(err => { + const errorMessage = 'Error while finding user pdl : ' + err.message + log('error', errorMessage) + Sentry.captureException(errorMessage, { + tags: { + section: 'findUserPdl', + }, + extra: { + address: address, + postalCode: postalCode, + escalierEtEtageEtAppartement: escalierEtEtageEtAppartement, + }, + }) + throw new Error(errors.VENDOR_DOWN) + }) + + const parsedReply = await xml2js.parseStringPromise(response.body, { + tagNameProcessors: [parseTags], + valueProcessors: [parseValue], + explicitArray: false, + }) + + try { + return parseUserPdl(parsedReply) + } catch (error) { + log('warn', 'Error while parsing user PDL: ' + error) + if (parsedReply.Envelope.Body.Fault) { + log( + 'warn', + `Enedis issue ${parsedReply.Envelope.Body.Fault.detail.erreur.resultat.$.code}: ${parsedReply.Envelope.Body.Fault.faultstring}` + ) + } + return null + } + } catch (error) { + log('error', 'Error while findingUserPdl', error) + Sentry.captureException(error, { tags: { section: 'findUserPdl', }, - extra: { - address: address, - postalCode: postalCode, - escalierEtEtageEtAppartement: escalierEtEtageEtAppartement, - }, }) throw new Error(errors.VENDOR_DOWN) - }) - - const parsedReply = await xml2js.parseStringPromise(response.body, { - tagNameProcessors: [parseTags], - valueProcessors: [parseValue], - explicitArray: false, - }) - - try { - return parseUserPdl(parsedReply) - } catch (error) { - log('warn', 'Error while parsing user PDL: ' + error) - if (parsedReply.Envelope.Body.Fault) { - log( - 'warn', - `Enedis issue ${parsedReply.Envelope.Body.Fault.detail.erreur.resultat.$.code}: ${parsedReply.Envelope.Body.Fault.faultstring}` - ) - } - return null } }