diff --git a/src/index.js b/src/index.js index afd337881933f4b8d9e048c549e911db1fa98512..4ca3bea3f3d386ebabc668349b48890d5bb50e8b 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 } }