From 4b0ee26333a8c9407e23f0a1e3e250a257a55629 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20PAILHAREY?= <rpailharey@grandlyon.com> Date: Thu, 11 Apr 2024 14:40:28 +0000 Subject: [PATCH] feat: better sentry logs --- src/index.js | 13 +++++++++++-- src/onDeleteAccount.js | 6 +++++- src/requests/grdf.js | 16 +++++++++++++++- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/index.js b/src/index.js index 2e7bc34..f298312 100755 --- a/src/index.js +++ b/src/index.js @@ -136,7 +136,11 @@ async function start(fields, cozyParameters) { } } catch (error) { log('error', 'Start failed', error) - Sentry.captureException(error) + Sentry.captureException(error, { + tags: { + section: 'start' + } + }) await Sentry.flush() throw error } @@ -199,7 +203,12 @@ async function getData(token, idPCE, startDate, endDate) { result.periode.date_fin ) Sentry.captureMessage( - `Get data threw an error: ${result.statut_restitution.code} - ${result.statut_restitution.message}` + `Get data threw an error: ${result.statut_restitution.code} - ${result.statut_restitution.message}`, + { + tags: { + section: 'getData' + } + } ) throw genError } else { diff --git a/src/onDeleteAccount.js b/src/onDeleteAccount.js index 081a184..77dc550 100644 --- a/src/onDeleteAccount.js +++ b/src/onDeleteAccount.js @@ -20,7 +20,11 @@ onDeleteAccount().then( err => { const errorMessage = `onDeleteAccount GRDF: An error occurred during script: ${err.message}` log('error', errorMessage) - Sentry.captureException(errorMessage) + Sentry.captureException(errorMessage, { + tags: { + section: 'onDeleteAccount' + } + }) } ) diff --git a/src/requests/grdf.js b/src/requests/grdf.js index 86d9083..1895664 100644 --- a/src/requests/grdf.js +++ b/src/requests/grdf.js @@ -30,6 +30,11 @@ async function getAuthToken(client_id, client_secret) { return response.data } catch (error) { log('error', 'Error inside getAuthToken', error) + Sentry.captureException('Error while getting auth token', { + tags: { + section: 'getAuthToken' + } + }) throw errors.VENDOR_DOWN } } @@ -69,6 +74,11 @@ async function getConsents(bearerToken, pce) { } catch (error) { log('error', 'Error while getting consent') log('error', error) + Sentry.captureException('Error while getting consent', { + tags: { + section: 'getConsents' + } + }) throw errors.VENDOR_DOWN } } @@ -110,7 +120,11 @@ async function createGRDFConsent({ } catch (error) { log('error', `Failed to create GRDF consent`) log('error', error.response.data) - Sentry.captureException('Failed to create GRDF consent') + Sentry.captureException('Failed to create GRDF consent', { + tags: { + section: 'createGRDFConsent' + } + }) throw errors.USER_ACTION_NEEDED_CGU_FORM } } -- GitLab