diff --git a/src/index.js b/src/index.js index 9a1d7e996c5871805af3224728559fd9cb0e341b..1053b32e59e01e1228fd53bb0008b7ff258a0614 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,12 @@ 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}`) } + 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 +234,10 @@ async function authenticate(login, password, baseUrl, apiAuthKey) { compte: login, }, }) - throw new Error(errors.LOGIN_FAILED) + if (error.response?.data.codeRetour === -4) { + throw new Error(errors.LOGIN_FAILED) + } + throw new Error(errors.VENDOR_DOWN) } }