Skip to content
Snippets Groups Projects
Commit 7c753a43 authored by Hugo NOUTS's avatar Hugo NOUTS
Browse files

fix(getData): added vendor_down error to new codes responses from grdf

parent 8e4e5f07
No related branches found
No related tags found
3 merge requests!6Dev to master,!5Dev,!4fix(getData): added vendor_down error to new codes responses from grdf
{ {
"version": "1.0.2", "version": "1.0.3",
"name": "GRDF", "name": "GRDF",
"type": "konnector", "type": "konnector",
"language": "node", "language": "node",
......
{ {
"name": "grdf", "name": "grdf",
"version": "1.0.2", "version": "1.0.3",
"description": "", "description": "",
"repository": { "repository": {
"type": "git", "type": "git",
......
/*
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
...@@ -8,6 +8,7 @@ const { ...@@ -8,6 +8,7 @@ const {
} = require('cozy-konnector-libs') } = require('cozy-konnector-libs')
const getAccountId = require('./helpers/getAccountId') const getAccountId = require('./helpers/getAccountId')
const isVendorDown = require('./helpers/isVendorDown')
const moment = require('moment') const moment = require('moment')
require('moment-timezone') require('moment-timezone')
...@@ -121,9 +122,11 @@ async function getData(token, idPCE) { ...@@ -121,9 +122,11 @@ async function getData(token, idPCE) {
if (result.statut_restitution !== null) { if (result.statut_restitution !== null) {
log( log(
'warn', 'warn',
'USER_ACTION_NEEDED_OAUTH_OUTDATED : ' + 'GET DATA THREW AN ERROR : ' +
result.statut_restitution.code +
' -> ' +
result.statut_restitution.message + result.statut_restitution.message +
' / Period: ' + ' Period: ' +
result.periode.date_debut + result.periode.date_debut +
'/' + '/' +
result.periode.date_fin result.periode.date_fin
...@@ -134,9 +137,14 @@ async function getData(token, idPCE) { ...@@ -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 there is no data, return null data in order to be filtered before saving
*/ */
if (result.statut_restitution.code !== '1000008') { 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 return result.consommation
}) })
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment