diff --git a/src/index.js b/src/index.js index 98ffc025a3378ccaf2e423d5d9a6f50bc5f0af7c..e094bb399dcd113a402d2019b97d4f98a966d6ef 100644 --- a/src/index.js +++ b/src/index.js @@ -134,7 +134,9 @@ async function start(fields, cozyParameters) { ) { const errorMessage = 'Missing configuration secrets' log('error', errorMessage) - Sentry.captureException(errorMessage) + Sentry.captureException(errorMessage, { + tags: { section: 'start' }, + }) throw new Error(errors.VENDOR_DOWN) } @@ -246,7 +248,9 @@ async function start(fields, cozyParameters) { if (!userConsent) { const errorMessage = 'No user consent found' log('error', errorMessage) - Sentry.captureException(errorMessage) + Sentry.captureException(errorMessage, { + tags: { section: 'start' }, + }) throw new Error(errors.VENDOR_DOWN) } @@ -330,11 +334,15 @@ async function deleteConsent( } else { const errorMessage = `No service id retrieved from BO` log('error', errorMessage) - Sentry.captureException(errorMessage) + Sentry.captureException(errorMessage, { + tags: { section: 'start' }, + }) throw new Error(errors.VENDOR_DOWN) } if (isConsentExpired) { - Sentry.captureException('Consent expired') + Sentry.captureException('Consent expired', { + tags: { section: 'start' }, + }) throw new Error(errors.USER_ACTION_NEEDED_OAUTH_OUTDATED) } throw new Error(errors.TERMS_VERSION_MISMATCH) @@ -410,7 +418,9 @@ async function getData(url, apiAuthKey, userLogin, pointId) { }).catch(err => { log('error', 'consultationMesuresDetaillees') log('error', err) - Sentry.captureException('consultationMesuresDetaillees:', err) + Sentry.captureException(`consultationMesuresDetaillees: ${err}`, { + tags: { section: 'getData' }, + }) return err }) @@ -453,7 +463,9 @@ async function getMaxPowerData(url, apiAuthKey, userLogin, pointId) { }).catch(err => { log('error', 'getMaxPowerData') log('error', err) - Sentry.captureException('getMaxPowerDate') + Sentry.captureException(`getMaxPowerData: ${err}`, { + tags: { section: 'getMaxPowerData' }, + }) return err }) @@ -506,7 +518,7 @@ async function getDataHalfHour(url, apiAuthKey, userLogin, pointId) { // If manual execution, retrieve only 1 week otherwise retrieve 4 weeks const MAX_HISTO = manualExecution ? 1 : 4 - for (var i = 0; i < MAX_HISTO; i++) { + for (let i = 0; i < MAX_HISTO; i++) { log('info', 'launch process with history') const incrementedStartDateString = moment(startLoadDate) .subtract(7 * i, 'day') @@ -529,7 +541,12 @@ async function getDataHalfHour(url, apiAuthKey, userLogin, pointId) { }).catch(err => { log('error', 'consultationMesuresDetaillees half-hour') log('error', err) - Sentry.captureException('consultationMesuresDetaillees half-hour') + Sentry.captureException( + `consultationMesuresDetaillees half-hour: ${err}`, + { + tags: { section: 'getDataHalfHour' }, + } + ) return err }) @@ -575,7 +592,9 @@ function processData(doctype = 'com.grandlyon.enedis.day') { } catch (e) { if (doctype === 'com.grandlyon.enedis.minute') { const errorMessage = `No half-hour activated. Issue: ${result.Envelope.Body.Fault.faultstring}` - Sentry.captureMessage(errorMessage) + Sentry.captureMessage(errorMessage, { + tags: { section: 'processData' }, + }) log('warn', errorMessage) } else { log('warn', `Unknown error ${e}`)