diff --git a/manifest.konnector b/manifest.konnector index f2b10bbe98f69c16516f07cc450e333f5ac137eb..18cabefb2977618281296ba253bd5bd7c906f355 100755 --- a/manifest.konnector +++ b/manifest.konnector @@ -1,5 +1,5 @@ { - "version": "1.0.2", + "version": "1.0.3", "name": "GRDF", "type": "konnector", "language": "node", diff --git a/package.json b/package.json index f262725d57f06b1f8ec131801b947b562113777d..abce1af539dd2c792f6781d6c991c6a022ea812e 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "grdf", - "version": "1.0.2", + "version": "1.0.3", "description": "", "repository": { "type": "git", diff --git a/src/helpers/isVendorDown.js b/src/helpers/isVendorDown.js new file mode 100644 index 0000000000000000000000000000000000000000..f3edb9bdca375f96f826ad4c0673d37326868b2c --- /dev/null +++ b/src/helpers/isVendorDown.js @@ -0,0 +1,21 @@ +/* +Error handling is based on API GRDF ADICT_Messages erreurs B2B_PROD_v1.4 +some code number can be duplicated depending on the http status +isVendorDown only handle codes associated with http 200 response, all http error should be catched beforehand. +*/ +function isVendorDown(code) { + switch (code) { + case '2000100': + case '1000009': + case '1000010': + case '1000011': + case '1000006': + case '1000016': + case '1000000': + return true + default: + return false + } +} + +module.exports = isVendorDown diff --git a/src/index.js b/src/index.js index 384513e0da8cdfa49cee0c084c8a58e522226e3c..6dec2afa0c1303276beaea8a555950dae84e0db2 100755 --- a/src/index.js +++ b/src/index.js @@ -8,6 +8,7 @@ const { } = require('cozy-konnector-libs') const getAccountId = require('./helpers/getAccountId') +const isVendorDown = require('./helpers/isVendorDown') const moment = require('moment') require('moment-timezone') @@ -121,9 +122,11 @@ async function getData(token, idPCE) { if (result.statut_restitution !== null) { log( 'warn', - 'USER_ACTION_NEEDED_OAUTH_OUTDATED : ' + + 'GET DATA THREW AN ERROR : ' + + result.statut_restitution.code + + ' -> ' + result.statut_restitution.message + - ' / Period: ' + + ' Period: ' + result.periode.date_debut + '/' + result.periode.date_fin @@ -134,9 +137,14 @@ async function getData(token, idPCE) { * If there is no data, return null data in order to be filtered before saving */ if (result.statut_restitution.code !== '1000008') { - throw errors.USER_ACTION_NEEDED_OAUTH_OUTDATED + if (isVendorDown(result.statut_restitution.code)) { + throw errors.VENDOR_DOWN + } else { + throw errors.USER_ACTION_NEEDED_OAUTH_OUTDATED + } + } else { + return { energie: null } } - return { energie: null } } return result.consommation })