From d4f5b46a5b093aa5b0a9682acdd76ec5b725a6b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Pailharey?= <rpailharey@grandlyon.com> Date: Wed, 23 Aug 2023 10:53:38 +0200 Subject: [PATCH] review: added tags and extra --- src/core/contractActivation.js | 15 +++++-- src/core/contractStartDate.js | 9 +++- src/core/contractTermination.js | 24 ++++++++-- src/core/contractVerification.js | 20 +++++++-- src/core/findUserAddress.js | 15 ++++++- src/core/findUserPdl.js | 15 +++++-- src/requests/bo.js | 77 ++++++++++++++++++++++---------- 7 files changed, 134 insertions(+), 41 deletions(-) diff --git a/src/core/contractActivation.js b/src/core/contractActivation.js index 3b9fd32..e4bb806 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 09d1124..e51427d 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 51d7be7..07c333d 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 a801941..a224201 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 6494068..d9d5865 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 5df60bc..c438d84 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 bea22b9..aeb0165 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) } } -- GitLab