From 3285ec7eb551eeaa7f7f4b1b98c6c93c247cb104 Mon Sep 17 00:00:00 2001
From: Bastien Dumont <bastienxs@gmail.com>
Date: Fri, 22 Sep 2023 11:10:22 +0200
Subject: [PATCH] vendor down

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

diff --git a/src/index.js b/src/index.js
index 9a1d7e9..70e1203 100644
--- a/src/index.js
+++ b/src/index.js
@@ -202,6 +202,7 @@ async function buildAggregatedData(data, doctype) {
 }
 
 async function authenticate(login, password, baseUrl, apiAuthKey) {
+  log('info', 'Authenticating ...')
   const authRequest = {
     method: 'post',
     url: baseUrl + '/connect.aspx',
@@ -219,13 +220,14 @@ async function authenticate(login, password, baseUrl, apiAuthKey) {
     const resp = await axios(authRequest)
     if (resp.data.codeRetour === 100) {
       return resp.data
-    } else {
-      const errorMessage = `Authentication failed. Response data: ${resp.data.libelleRetour}`
-      log('debug', errorMessage)
-      throw new Error(`code retour ko : ${resp.data.codeRetour}`)
+    } else if (resp.data.codeRetour === -4) {
+      throw new Error(errors.LOGIN_FAILED)
     }
+    const errorMessage = `Authentication failed. Response data: ${resp?.data?.libelleRetour}`
+    log('error', errorMessage)
+    throw new Error(errors.VENDOR_DOWN)
   } catch (error) {
-    log('debug', error.message)
+    log('error', error.response?.data)
     Sentry.captureException(error, {
       tags: {
         section: 'authenticate',
@@ -234,7 +236,7 @@ async function authenticate(login, password, baseUrl, apiAuthKey) {
         compte: login,
       },
     })
-    throw new Error(errors.LOGIN_FAILED)
+    throw error
   }
 }
 
-- 
GitLab