diff --git a/src/core/contractActivation.js b/src/core/contractActivation.js index 3b9fd32a2b02c616ded9f17f1f0ddd49b3644bef..e4bb80660f4e0f195104a63c9415fd89c00faf2b 100644 --- a/src/core/contractActivation.js +++ b/src/core/contractActivation.js @@ -44,9 +44,18 @@ async function activateContract( endDate ), }).catch(err => { - log('error', 'commanderCollectePublicationMesures') - log('error', err) - Sentry.captureException('commanderCollectePublicationMesures', err) + const errorMessage = `Error while activating contract : ${err}` + log('debug', errorMessage) + Sentry.captureException(errorMessage, { + tags: { + section: 'activateContract', + }, + extra: { + pointId: pointId, + dates: [startDate, endDate], + }, + }) + throw new Error(errors.CAPTCHA_RESOLUTION_FAILED) }) diff --git a/src/core/contractStartDate.js b/src/core/contractStartDate.js index 09d11244c1bcfd0f3081d377d8dd87cfc8d2ca10..e51427db013cae8b764ba5f1087fbd1ce613ae5e 100644 --- a/src/core/contractStartDate.js +++ b/src/core/contractStartDate.js @@ -32,7 +32,14 @@ async function getContractStartDate(url, apiAuthKey, userLogin, pointId) { }).catch(err => { const errorMessage = 'Error while fetching contract start date : ' + err log('error', errorMessage) - Sentry.captureException(errorMessage) + Sentry.captureException(errorMessage, { + tags: { + section: 'getContractStartDate', + }, + extra: { + pointId: pointId, + }, + }) throw new Error(errors.VENDOR_DOWN) }) diff --git a/src/core/contractTermination.js b/src/core/contractTermination.js index 51d7be7f8a469e0bc2a162fa2c6b899d3ecd1381..07c333de6bcd2301d5d77f0a8e7ec15e4f465691 100644 --- a/src/core/contractTermination.js +++ b/src/core/contractTermination.js @@ -38,9 +38,18 @@ async function terminateContract( serviceId ), }).catch(err => { - log('error', 'commanderArretServiceSouscritMesures') - log('error', err) - Sentry.captureException('commanderArretServiceSouscritMesures', err) + const errorMessage = 'Error while terminating contract : ' + err + log('error', errorMessage) + Sentry.captureException(errorMessage, { + tags: { + section: 'terminateContract', + }, + extra: { + contractId: contractId, + pointId: pointId, + serviceId: serviceId, + }, + }) throw new Error(errors.VENDOR_DOWN) }) @@ -64,7 +73,14 @@ async function terminateContract( 'Error while parsing user contract termination: ' + error log('error', errorMessage) log('error', `Enedis issue ${JSON.stringify(parsedReply.Envelope.Body)}`) - Sentry.captureException(errorMessage) + Sentry.captureException(errorMessage, { + tags: { + section: 'terminateContract', + }, + extra: { + pointId: pointId, + }, + }) throw new Error(errors.VENDOR_DOWN) } } diff --git a/src/core/contractVerification.js b/src/core/contractVerification.js index a801941bb4dc2f263fc7c57c437f82410765b283..a2242010579dbe0748ae3af8a11d3e982070627a 100644 --- a/src/core/contractVerification.js +++ b/src/core/contractVerification.js @@ -31,9 +31,17 @@ async function verifyContract(url, apiAuthKey, appLogin, contractId, pointId) { headers: sgeHeaders, xml: rechercherServicesSouscritsMesures(appLogin, contractId, pointId), }).catch(err => { - log('error', 'rechercherServicesSouscritsMesures') - log('error', err) - Sentry.captureException('rechercherServicesSouscritsMesures', err) + const errorMessage = 'Error while verifying contract : ' + err + log('error', errorMessage) + Sentry.captureException(errorMessage, { + tags: { + section: 'verifyContract', + }, + extra: { + contractId: contractId, + pointId: pointId, + }, + }) throw new Error(errors.CAPTCHA_RESOLUTION_FAILED) }) @@ -66,7 +74,11 @@ async function verifyContract(url, apiAuthKey, appLogin, contractId, pointId) { } catch (error) { const errorMessage = 'Error while parsing user contract: ' + error log('error', errorMessage) - Sentry.captureException(errorMessage) + Sentry.captureException(errorMessage, { + tags: { + section: 'verifyContract', + }, + }) if (parsedReply.Envelope.Body.Fault) { log( 'error', diff --git a/src/core/findUserAddress.js b/src/core/findUserAddress.js index 64940685f9204eec1164811378605225d8966718..d9d58655061674ae8d13613a7840c0e26fac6889 100644 --- a/src/core/findUserAddress.js +++ b/src/core/findUserAddress.js @@ -32,7 +32,14 @@ async function findUserAddress(url, apiAuthKey, userLogin, pointId) { }).catch(err => { const errorMessage = 'Error while fetching user : ' + err log('error', errorMessage) - Sentry.captureException(errorMessage) + Sentry.captureException(errorMessage, { + tags: { + section: 'findUserAddress', + }, + extra: { + pointId: pointId, + }, + }) throw new Error(errors.VENDOR_DOWN) }) @@ -51,7 +58,11 @@ async function findUserAddress(url, apiAuthKey, userLogin, pointId) { 'error', `Enedis issue ${result.Envelope.Body.Fault.detail.erreur.resultat.$.code}: ${result.Envelope.Body.Fault.faultstring}` ) - Sentry.captureException(errorMessage) + Sentry.captureException(errorMessage, { + tags: { + section: 'findUserAddress', + }, + }) throw new Error(errors.LOGIN_FAILED) } } diff --git a/src/core/findUserPdl.js b/src/core/findUserPdl.js index 5df60bc37a22e6a501757cdc828257e0b4b62907..c438d841687f7c32cc117a7923394260eeecb069 100644 --- a/src/core/findUserPdl.js +++ b/src/core/findUserPdl.js @@ -44,9 +44,18 @@ async function findUserPdl( escalierEtEtageEtAppartement ), }).catch(err => { - log('error', 'rechercherPointResponse') - log('error', err) - Sentry.captureException('rechercherPointResponse', err) + const errorMessage = 'Error while finding user pdl : ' + err + log('error', errorMessage) + Sentry.captureException(errorMessage, { + tags: { + section: 'findUserPdl', + }, + extra: { + address: address, + postalCode: postalCode, + escalierEtEtageEtAppartement: escalierEtEtageEtAppartement, + }, + }) throw new Error(errors.LOGIN_FAILED) }) diff --git a/src/requests/bo.js b/src/requests/bo.js index bea22b9308b7e08f16d8d4f89d01bbda1436274b..aeb01656f3b8e315fc605d9200e9c4c4cac33485 100644 --- a/src/requests/bo.js +++ b/src/requests/bo.js @@ -49,10 +49,18 @@ async function createBoConsent( headers ) return data - } catch (e) { - const errorMessage = `BO replied with ${e}` + } catch (err) { + const errorMessage = 'Error while creating BO consent : ' + err log('error', errorMessage) - Sentry.captureException(errorMessage) + Sentry.captureException(errorMessage, { + tags: { + section: 'createBoConsent', + }, + extra: { + pointID: pointID, + safetyOnBoarding: safetyOnBoarding, + }, + }) throw new Error(errors.MAINTENANCE) } } @@ -72,11 +80,11 @@ async function updateBoConsent(url, token, consent, serviceId) { }, } + let consentId = '' + if (consent.ID) { + consentId = consent.ID.toString() + } try { - let consentId = '' - if (consent.ID) { - consentId = consent.ID.toString() - } const { data } = await axios.put( `${url}/consent/${consentId}`, { @@ -86,32 +94,46 @@ async function updateBoConsent(url, token, consent, serviceId) { headers ) return data - } catch (e) { - const errorMessage = `BO replied with ${e}` + } catch (err) { + const errorMessage = 'Error while updating BO consent : ' + err log('error', errorMessage) - Sentry.captureException(errorMessage) + Sentry.captureException(errorMessage, { + tags: { + section: 'updateBoConsent', + }, + extra: { + consentId: consentId, + }, + }) throw new Error(errors.MAINTENANCE) } } /** - * @param {number} boId + * @param {number} consentId * @returns {Promise<Consent>} */ -async function getBoConsent(url, token, boId) { - log('info', `Query getBoConsent ${boId}`) +async function getBoConsent(url, token, consentId) { + log('info', `Query getBoConsent ${consentId}`) const headers = { headers: { Authorization: `Bearer ${token}`, }, } try { - const { data } = await axios.get(`${url}/consent/${boId}`, headers) + const { data } = await axios.get(`${url}/consent/${consentId}`, headers) return data - } catch (e) { - const errorMessage = `BO replied with ${e}` + } catch (err) { + const errorMessage = 'Error while getting BO consent : ' + err log('error', errorMessage) - Sentry.captureException(errorMessage) + Sentry.captureException(errorMessage, { + tags: { + section: 'getBoConsent', + }, + extra: { + consentId: consentId, + }, + }) throw new Error(errors.MAINTENANCE) } } @@ -120,23 +142,30 @@ async function getBoConsent(url, token, boId) { * Delete BO consent * @param {string} url * @param {string} token - * @param {number} boId + * @param {number} consentId * @returns */ -async function deleteBoConsent(url, token, boId) { - log('info', `Query deleteBoConsent ${boId}`) +async function deleteBoConsent(url, token, consentId) { + log('info', `Query deleteBoConsent ${consentId}`) const headers = { headers: { Authorization: `Bearer ${token}`, }, } try { - const { data } = await axios.delete(`${url}/consent/${boId}`, headers) + const { data } = await axios.delete(`${url}/consent/${consentId}`, headers) return data - } catch (e) { - const errorMessage = `BO replied with ${e}` + } catch (err) { + const errorMessage = 'Error while deleting BO consent : ' + err log('error', errorMessage) - Sentry.captureException(errorMessage) + Sentry.captureException(errorMessage, { + tags: { + section: 'deleteBoConsent', + }, + extra: { + consentId: consentId, + }, + }) throw new Error(errors.MAINTENANCE) } }