Commit c8b322f8 authored by Hugo NOUTS's avatar Hugo NOUTS
Browse files

Merge branch 'getData-vendor-down' into 'dev'

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

See merge request !4
parents 8e4e5f07 7c753a43
{
"version": "1.0.2",
"version": "1.0.3",
"name": "GRDF",
"type": "konnector",
"language": "node",
......
{
"name": "grdf",
"version": "1.0.2",
"version": "1.0.3",
"description": "",
"repository": {
"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 {
} = 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
})
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment