From f4d02eb4d6c0369c74d21b8649d5ca4279308ff4 Mon Sep 17 00:00:00 2001
From: Bastien DUMONT <bdumont@grandlyon.com>
Date: Thu, 8 Dec 2022 13:54:58 +0100
Subject: [PATCH] log once per second change onboarding

---
 src/core/findUserPdl.js        |  4 +---
 src/core/verifyUserIdentity.js | 14 ++++++++++----
 2 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/src/core/findUserPdl.js b/src/core/findUserPdl.js
index 0e51a8a..7b41735 100644
--- a/src/core/findUserPdl.js
+++ b/src/core/findUserPdl.js
@@ -59,9 +59,7 @@ async function findUserPdl(
   try {
     return parseUserPdl(parsedReply)
   } catch (error) {
-    const errorMessage = 'Error while parsing user PDL: ' + error
-    log('warn', errorMessage)
-    Sentry.captureException(errorMessage)
+    log('warn', 'Error while parsing user PDL: ' + error)
     if (parsedReply.Envelope.Body.Fault) {
       log(
         'warn',
diff --git a/src/core/verifyUserIdentity.js b/src/core/verifyUserIdentity.js
index ec148e3..188d0aa 100644
--- a/src/core/verifyUserIdentity.js
+++ b/src/core/verifyUserIdentity.js
@@ -47,8 +47,9 @@ async function verifyUserIdentity(
   )
 
   if (!pdl) {
-    log('warn', 'Second chance for sge onboarding')
-    // TODO add "Second chance" to Sentry transaction
+    const warningMessage = 'Second chance for sge onboarding'
+    log('warn', warningMessage)
+    Sentry.captureMessage(warningMessage)
     // Set safety onboarding in order to save it inside BO
     userSafetyOnBoarding = true
     // Backup verification
@@ -87,9 +88,10 @@ async function verifyUserIdentity(
         userAddress.commune.$.code
       )
     }
-    // Third try, remove address number and add escalierEtEtageEtAppartement because it's buggy on SGE side
+
+    // Fourth try, remove address number and add escalierEtEtageEtAppartement because it's buggy on SGE side
     if (!pdl) {
-      log('warn', 'Last chance onboarding for sge')
+      log('warn', 'Fourth chance onboarding for sge')
       pdl = await findUserPdl(
         `${baseUrl}/enedis_SDE_recherche-point/1.0`,
         apiAuthKey,
@@ -101,6 +103,10 @@ async function verifyUserIdentity(
         escalierEtEtageEtAppartement
       )
     }
+
+    if (!pdl) {
+      Sentry.captureException('Second chance failed, no pdl found')
+    }
   }
 
   if (fields.pointId != pdl) {
-- 
GitLab