From 81c08677fe9f166b67a43a646f8599e96509a80b Mon Sep 17 00:00:00 2001
From: build-token <build-token>
Date: Tue, 30 Jul 2024 08:46:12 +0000
Subject: [PATCH] publish: Catch error serviceSouscritId

generated from commit 8ddfa79079fdb0df8209b549a5571ddc89f4fa8f
---
 index.js | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/index.js b/index.js
index 0e5078e..0c4aab2 100644
--- a/index.js
+++ b/index.js
@@ -297573,9 +297573,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