From 0e8c574d83ecf60699a9e3afe5880d4ffd2c85f0 Mon Sep 17 00:00:00 2001
From: hnouts <hnouts@grandlyon.com>
Date: Thu, 15 Jun 2023 14:47:55 +0200
Subject: [PATCH] wip

---
 src/index.js | 32 ++++++++++++++++++++++++++------
 1 file changed, 26 insertions(+), 6 deletions(-)

diff --git a/src/index.js b/src/index.js
index afd3378..4ca3bea 100644
--- a/src/index.js
+++ b/src/index.js
@@ -208,23 +208,25 @@ async function authenticate(login, password, baseUrl, apiAuthKey) {
       pass: password,
     },
   }
+
   try {
     const resp = await axios(authRequest)
     if (resp.data.codeRetour === 100) {
       return resp.data
     } else {
-      Sentry.captureException(JSON.stringify(resp.data))
+      const errorMessage = `Authentication failed. Response data: ${JSON.stringify(
+        resp.data
+      )}`
+      Sentry.captureMessage(errorMessage)
       throw new Error()
     }
   } catch (error) {
-    Sentry.captureException(JSON.stringify(error))
+    Sentry.captureException(error)
     throw new Error(errors.LOGIN_FAILED)
   }
 }
 
 async function getData(response, baseUrl, apiAuthKey) {
-  log('debug', 'Start date : ' + startDate)
-  log('debug', 'End date : ' + endDate)
   const dataRequest = {
     method: 'post',
     url: baseUrl + '/getAllAgregatsByAbonnement.aspx',
@@ -250,15 +252,33 @@ async function getData(response, baseUrl, apiAuthKey) {
       case 100:
         return format(resp.data)
       case -2:
+        Sentry.captureMessage(
+          `Get data failed. codeRetour - 2. Response data: ${JSON.stringify(
+            resp.data
+          )}`
+        )
         throw errors.LOGIN_FAILED
       case -1:
+        Sentry.captureMessage(
+          `Get data failed. codeRetour - 1. Response data: ${JSON.stringify(
+            resp.data
+          )}`
+        )
         throw errors.VENDOR_DOWN
       default:
+        Sentry.captureMessage(
+          `Get data failed. Unknown error occurred. Response data: ${JSON.stringify(
+            resp.data
+          )}`
+        )
         throw errors.UNKNOWN_ERROR
     }
   } catch (error) {
-    log('debug', 'Error from getAllAgregatsByAbonnement')
-    throw new Error(errors.VENDOR_DOWN)
+    if (axios.isAxiosError(error)) {
+      throw new Error(errors.VENDOR_DOWN)
+    }
+    Sentry.captureException(error)
+    throw error
   }
 }
 
-- 
GitLab