diff --git a/index.js b/index.js index 7e3b43010313b33ea0a24088989be1933b4ee999..9ca5c603411ff4530ec075de5453a20b1f502e50 100644 --- a/index.js +++ b/index.js @@ -114,8 +114,14 @@ async function start(fields, cozyParameters) { transaction.setStatus(Tracing.SpanStatus.Ok) transaction.finish() } catch (error) { - log('error', error) - Sentry.captureException(error) + const errorMessage = `EGL konnector encountered an error. Response data: ${JSON.stringify( + error.message + )}` + Sentry.captureMessage(errorMessage, { + tags: { + section: 'start', + }, + }) transaction.setStatus(Tracing.SpanStatus.Aborted) transaction.finish() await Sentry.flush() @@ -213,23 +219,31 @@ 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)) - throw new Error() + const errorMessage = `Authentication failed. Response data: ${resp.data.libelleRetour}` + log('debug', errorMessage) + throw new Error(`code retour ko : ${resp.data.codeRetour}`) } } catch (error) { - Sentry.captureException(JSON.stringify(error)) + log('debug', error.message) + Sentry.captureException(error, { + tags: { + section: 'authenticate', + }, + extra: { + compte: login, + }, + }) 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', @@ -255,51 +269,91 @@ async function getData(response, baseUrl, apiAuthKey) { case 100: return format(resp.data) case -2: + log( + 'error', + `Get data failed. codeRetour -2. ${resp.data.libelleRetour}` + ) throw errors.LOGIN_FAILED case -1: + log( + 'error', + `Get data failed. codeRetour -1. ${resp.data.libelleRetour}` + ) throw errors.VENDOR_DOWN default: + log( + 'error', + `Get data failed. ${resp.data.codeRetour}. ${resp.data.libelleRetour}` + ) throw errors.UNKNOWN_ERROR } } catch (error) { - log('debug', 'Error from getAllAgregatsByAbonnement') - throw new Error(errors.VENDOR_DOWN) + log('debug', error.message) + Sentry.captureException(error, { + tags: { + section: 'getData', + }, + extra: { + start: startDate, + end: endDate, + }, + }) + if (axios.isAxiosError(error)) { + throw new Error(errors.VENDOR_DOWN) + } + throw error } } function format(response) { - log('info', 'origin response size is : ' + response.resultatRetour.length) + log('info', 'origin response size is: ' + response.resultatRetour.length) // Store first value as reference for index processing let refValue = response.resultatRetour[0] + // Create copy of data without first value const data = response.resultatRetour .slice(1) .filter(value => value.ValeurIndex) - log('info', 'filtered size is : ' + data.length) - return data.map(value => { - const time = moment(value.DateReleve, moment.ISO_8601) - const processedLoad = value.ValeurIndex - refValue.ValeurIndex - if (processedLoad < 0) { - log( - 'error', - `processing load for day ${parseInt(time.format('D'))}/${parseInt( - time.format('M') - )}/${parseInt(time.format('YYYY'))}, value is : ${processedLoad}` - ) - throw errors.VENDOR_DOWN - } - // Change index ref value - refValue = value - return { - load: processedLoad, - year: parseInt(time.format('YYYY')), - month: parseInt(time.format('M')), - day: parseInt(time.format('D')), - hour: 0, - minute: 0, - type: value.TypeAgregat, - } - }) + + log('info', 'filtered size is: ' + data.length) + + try { + return data.map(value => { + const time = moment(value.DateReleve, moment.ISO_8601) + const processedLoad = value.ValeurIndex - refValue.ValeurIndex + + if (processedLoad < 0) { + const errorMessage = `Processing load error for day ${parseInt( + time.format('D') + )}/${parseInt(time.format('M'))}/${parseInt( + time.format('YYYY') + )}, value is: ${processedLoad}` + log('debug', errorMessage) + throw errors.VENDOR_DOWN + } + + // Change index ref value + refValue = value + + return { + load: processedLoad, + year: parseInt(time.format('YYYY')), + month: parseInt(time.format('M')), + day: parseInt(time.format('D')), + hour: 0, + minute: 0, + type: value.TypeAgregat, + } + }) + } catch (error) { + log('debug', error.message) + Sentry.captureException(error, { + tags: { + section: 'format', + }, + }) + throw error + } } /** @@ -308,9 +362,6 @@ function format(response) { async function storeData(data, doctype, filterKeys) { log('debug', 'Store into ' + doctype) log('debug', 'Store into keys : ' + filterKeys) - // data.map(v => { - // log('info', 'Saving data ' + v.load + ' for ' + v.day + '/' + v.month + '/' + v.year) - // }) const filteredDocuments = await hydrateAndFilter(data, doctype, { keys: filterKeys, }) @@ -150136,7 +150187,7 @@ const fs = __webpack_require__(149); const path = __webpack_require__(142); -let manifest = typeof {"version":"1.2.1","name":"EGL","type":"konnector","language":"node","icon":"icon.png","slug":"eglgrandlyon","source":"https://forge.grandlyon.com/web-et-numerique/llle_project/egl-konnector.git","editor":"Métropole de Lyon","vendor_link":"www.grandlyon.com","frequency":"daily","categories":["energy"],"fields":{"login":{"type":"text"},"password":{"type":"password"},"advancedFields":{"folderPath":{"advanced":true,"isRequired":false}}},"data_types":[],"screenshots":[],"permissions":{"egl data":{"type":"com.grandlyon.egl.*"},"accounts":{"type":"io.cozy.accounts","verbs":["GET"]}},"developer":{"name":"Métropole de Lyon","url":"https://grandlyon.com"},"langs":["fr"],"locales":{"fr":{"short_description":"Courbe de charge depuis l'API Eau Publique du Grand Lyon","long_description":"Ce connecteur récupère la courbe de charge enregistrée par le compteur Téléo","permissions":{"egl data":{"description":"Requises pour accéder et stocker les données collectées par le compteur Téléo et exposées par les API Eau Publique du Grand Lyon (consommations d’eau au jour, mois et année)."},"accounts":{"description":"Utilisé pour accéder à vos données de consommation."}}},"en":{"short_description":"Water consumption data fetched from \"Eau Publique du Grand Lyon\" API","long_description":"This konnector fetches the data curve gathered by Téléo device.","permissions":{"egl data":{"description":"Required to access and store the data collected by the Téléo meter and exposed by Eau Publique du Grand Lyon APIs (daily, monthly and yearly consumption)."},"accounts":{"description":"Used to access your consumption data."}}}},"manifest_version":"2"} === 'undefined' ? {} : {"version":"1.2.1","name":"EGL","type":"konnector","language":"node","icon":"icon.png","slug":"eglgrandlyon","source":"https://forge.grandlyon.com/web-et-numerique/llle_project/egl-konnector.git","editor":"Métropole de Lyon","vendor_link":"www.grandlyon.com","frequency":"daily","categories":["energy"],"fields":{"login":{"type":"text"},"password":{"type":"password"},"advancedFields":{"folderPath":{"advanced":true,"isRequired":false}}},"data_types":[],"screenshots":[],"permissions":{"egl data":{"type":"com.grandlyon.egl.*"},"accounts":{"type":"io.cozy.accounts","verbs":["GET"]}},"developer":{"name":"Métropole de Lyon","url":"https://grandlyon.com"},"langs":["fr"],"locales":{"fr":{"short_description":"Courbe de charge depuis l'API Eau Publique du Grand Lyon","long_description":"Ce connecteur récupère la courbe de charge enregistrée par le compteur Téléo","permissions":{"egl data":{"description":"Requises pour accéder et stocker les données collectées par le compteur Téléo et exposées par les API Eau Publique du Grand Lyon (consommations d’eau au jour, mois et année)."},"accounts":{"description":"Utilisé pour accéder à vos données de consommation."}}},"en":{"short_description":"Water consumption data fetched from \"Eau Publique du Grand Lyon\" API","long_description":"This konnector fetches the data curve gathered by Téléo device.","permissions":{"egl data":{"description":"Required to access and store the data collected by the Téléo meter and exposed by Eau Publique du Grand Lyon APIs (daily, monthly and yearly consumption)."},"accounts":{"description":"Used to access your consumption data."}}}},"manifest_version":"2"}; +let manifest = typeof {"version":"1.2.2","name":"EGL","type":"konnector","language":"node","icon":"icon.png","slug":"eglgrandlyon","source":"https://forge.grandlyon.com/web-et-numerique/llle_project/egl-konnector.git","editor":"Métropole de Lyon","vendor_link":"www.grandlyon.com","frequency":"daily","categories":["energy"],"fields":{"login":{"type":"text"},"password":{"type":"password"},"advancedFields":{"folderPath":{"advanced":true,"isRequired":false}}},"data_types":[],"screenshots":[],"permissions":{"egl data":{"type":"com.grandlyon.egl.*"},"accounts":{"type":"io.cozy.accounts","verbs":["GET"]}},"developer":{"name":"Métropole de Lyon","url":"https://grandlyon.com"},"langs":["fr"],"locales":{"fr":{"short_description":"Courbe de charge depuis l'API Eau Publique du Grand Lyon","long_description":"Ce connecteur récupère la courbe de charge enregistrée par le compteur Téléo","permissions":{"egl data":{"description":"Requises pour accéder et stocker les données collectées par le compteur Téléo et exposées par les API Eau Publique du Grand Lyon (consommations d’eau au jour, mois et année)."},"accounts":{"description":"Utilisé pour accéder à vos données de consommation."}}},"en":{"short_description":"Water consumption data fetched from \"Eau Publique du Grand Lyon\" API","long_description":"This konnector fetches the data curve gathered by Téléo device.","permissions":{"egl data":{"description":"Required to access and store the data collected by the Téléo meter and exposed by Eau Publique du Grand Lyon APIs (daily, monthly and yearly consumption)."},"accounts":{"description":"Used to access your consumption data."}}}},"manifest_version":"2"} === 'undefined' ? {} : {"version":"1.2.2","name":"EGL","type":"konnector","language":"node","icon":"icon.png","slug":"eglgrandlyon","source":"https://forge.grandlyon.com/web-et-numerique/llle_project/egl-konnector.git","editor":"Métropole de Lyon","vendor_link":"www.grandlyon.com","frequency":"daily","categories":["energy"],"fields":{"login":{"type":"text"},"password":{"type":"password"},"advancedFields":{"folderPath":{"advanced":true,"isRequired":false}}},"data_types":[],"screenshots":[],"permissions":{"egl data":{"type":"com.grandlyon.egl.*"},"accounts":{"type":"io.cozy.accounts","verbs":["GET"]}},"developer":{"name":"Métropole de Lyon","url":"https://grandlyon.com"},"langs":["fr"],"locales":{"fr":{"short_description":"Courbe de charge depuis l'API Eau Publique du Grand Lyon","long_description":"Ce connecteur récupère la courbe de charge enregistrée par le compteur Téléo","permissions":{"egl data":{"description":"Requises pour accéder et stocker les données collectées par le compteur Téléo et exposées par les API Eau Publique du Grand Lyon (consommations d’eau au jour, mois et année)."},"accounts":{"description":"Utilisé pour accéder à vos données de consommation."}}},"en":{"short_description":"Water consumption data fetched from \"Eau Publique du Grand Lyon\" API","long_description":"This konnector fetches the data curve gathered by Téléo device.","permissions":{"egl data":{"description":"Required to access and store the data collected by the Téléo meter and exposed by Eau Publique du Grand Lyon APIs (daily, monthly and yearly consumption)."},"accounts":{"description":"Used to access your consumption data."}}}},"manifest_version":"2"}; if (process.env.NODE_ENV !== undefined && process.env.NODE_ENV !== 'none' && process.env.NODE_ENV !== 'production') { try { @@ -240367,7 +240418,7 @@ var SpanStatus; (function (SpanStatus) { /***/ ((module) => { "use strict"; -module.exports = JSON.parse('{"name":"egl","version":"1.2.1","description":"","repository":{"type":"git","url":"git+https://forge.grandlyon.com/web-et-numerique/llle_project/egl-konnector.git"},"keywords":[],"author":"Grand Lyon","license":"AGPL-3.0","main":"./src/index.js","eslintConfig":{"extends":["cozy-app"]},"eslintIgnore":["build"],"husky":{"hooks":{"pre-commit":"yarn lint"}},"scripts":{"start":"node ./src/index.js","dev":"cozy-konnector-dev","standalone":"cozy-konnector-standalone","pretest":"npm run clean","test":"konitor testit .","check":"konitor check .","clean":"rm -rf ./data","build":"webpack","lint":"eslint --fix .","deploy":"git-directory-deploy --directory build/ --branch ${DEPLOY_BRANCH:-build}","deploy-dev":"git-directory-deploy --directory build/ --branch ${DEPLOY_BRANCH:-build-dev}","cozyPublish":"cozy-app-publish --token $REGISTRY_TOKEN --build-commit $(git rev-parse ${DEPLOY_BRANCH:-build})","travisDeployKey":"./bin/generate_travis_deploy_key"},"dependencies":{"@sentry/node":"7.30.0","@sentry/tracing":"7.30.0","cozy-konnector-libs":"4.56.4","moment":"^2.24.0","moment-timezone":"^0.5.26","axios":"1.2.2"},"devDependencies":{"@types/moment-timezone":"^0.5.30","copy-webpack-plugin":"6.1.1","cozy-app-publish":"0.25.0","cozy-jobs-cli":"1.20.2","cozy-konnector-build":"1.4.4","eslint":"5.16.0","eslint-config-cozy-app":"1.6.0","eslint-plugin-prettier":"3.0.1","git-directory-deploy":"1.5.1","husky":"4.3.0","konitor":"0.10.2","standard-version":"^9.5.0","svgo":"1.3.2","webpack":"5.75.0","webpack-cli":"5.0.1"}}'); +module.exports = JSON.parse('{"name":"egl","version":"1.2.2","description":"","repository":{"type":"git","url":"git+https://forge.grandlyon.com/web-et-numerique/llle_project/egl-konnector.git"},"keywords":[],"author":"Grand Lyon","license":"AGPL-3.0","main":"./src/index.js","eslintConfig":{"extends":["cozy-app"]},"eslintIgnore":["build"],"husky":{"hooks":{"pre-commit":"yarn lint"}},"scripts":{"start":"node ./src/index.js","dev":"cozy-konnector-dev","standalone":"cozy-konnector-standalone","pretest":"npm run clean","test":"konitor testit .","check":"konitor check .","clean":"rm -rf ./data","build":"webpack","lint":"eslint --fix .","deploy":"git-directory-deploy --directory build/ --branch ${DEPLOY_BRANCH:-build}","deploy-dev":"git-directory-deploy --directory build/ --branch ${DEPLOY_BRANCH:-build-dev}","cozyPublish":"cozy-app-publish --token $REGISTRY_TOKEN --build-commit $(git rev-parse ${DEPLOY_BRANCH:-build})","travisDeployKey":"./bin/generate_travis_deploy_key"},"dependencies":{"@sentry/node":"7.30.0","@sentry/tracing":"7.30.0","cozy-konnector-libs":"4.56.4","moment":"^2.24.0","moment-timezone":"^0.5.26","axios":"1.2.2"},"devDependencies":{"@types/moment-timezone":"^0.5.30","copy-webpack-plugin":"6.1.1","cozy-app-publish":"0.25.0","cozy-jobs-cli":"1.20.2","cozy-konnector-build":"1.4.4","eslint":"5.16.0","eslint-config-cozy-app":"1.6.0","eslint-plugin-prettier":"3.0.1","git-directory-deploy":"1.5.1","husky":"4.3.0","konitor":"0.10.2","standard-version":"^9.5.0","svgo":"1.3.2","webpack":"5.75.0","webpack-cli":"5.0.1"}}'); /***/ }), /* 1647 */ diff --git a/manifest.konnector b/manifest.konnector index d38bbb35c83790ede1fe4e22066bc95729335fb2..366819339633ab86ef4a2aee878fc658554e0c4f 100644 --- a/manifest.konnector +++ b/manifest.konnector @@ -1,5 +1,5 @@ { - "version": "1.2.1", + "version": "1.2.2", "name": "EGL", "type": "konnector", "language": "node", diff --git a/package.json b/package.json index 5c19bf3fc4843a8555d1a0d7cd3a0ec98fd976d2..1f45ae39af011d381e590b7279dd9031e3581e45 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "egl", - "version": "1.2.1", + "version": "1.2.2", "description": "", "repository": { "type": "git",