diff --git a/src/index.js b/src/index.js index 9a1d7e996c5871805af3224728559fd9cb0e341b..70e120316791d4b5c0031115a4d7b6fe94785eba 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 } }