From 8de58555db837fdefbb9de4c9f67253afb50bc0f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9mi=20Pailharey?= <rpailharey@grandlyon.com>
Date: Mon, 11 Dec 2023 17:07:07 +0100
Subject: [PATCH] fix: delete BO consent if contact activation failed

---
 src/index.js | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/index.js b/src/index.js
index 6dc43d8..4df3db2 100644
--- a/src/index.js
+++ b/src/index.js
@@ -195,7 +195,10 @@ async function start(fields, cozyParameters) {
           user.pointId,
           contractStartDate,
           contractEndDate
-        )
+        ).catch(async err => {
+          await deleteBoConsent(boBaseUrl, boToken, consent.ID)
+          throw err
+        })
       }
       consent = await updateBoConsent(
         boBaseUrl,
-- 
GitLab