From 64f11512262381c2dd020d5733a946fbde2a932a Mon Sep 17 00:00:00 2001
From: Pierre Ecarlat <pecarlat@grandlyon.com>
Date: Tue, 30 Jul 2024 10:30:49 +0200
Subject: [PATCH] Catch error serviceSouscritId

---
 src/helpers/parsing.js | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/src/helpers/parsing.js b/src/helpers/parsing.js
index af11ce2..5613761 100644
--- a/src/helpers/parsing.js
+++ b/src/helpers/parsing.js
@@ -75,9 +75,22 @@ function parseContracts(result) {
 function parseServiceId(result) {
   log('info', 'Parsing serviceId')
   const json = JSON.stringify(result)
-  return JSON.parse(json)['Envelope']['Body'][
-    'commanderCollectePublicationMesuresResponse'
-  ]['serviceSouscritId']
+  const contractInfo =
+    JSON.parse(json)['Envelope']['Body'][
+      'commanderCollectePublicationMesuresResponse'
+    ]
+  if (contractInfo !== undefined) {
+    return contractInfo['serviceSouscritId']
+  } else {
+    const errorMessage =
+      "No serviceSouscritId found, contract hasn't been created properly."
+    Sentry.captureException(errorMessage, {
+      tags: {
+        section: 'parseServiceId',
+      },
+    })
+    throw new Error(errorMessage)
+  }
 }
 
 /**
-- 
GitLab