From e6e8ce69c0f9108df554a9d75baa1f8ea9f1d3a7 Mon Sep 17 00:00:00 2001 From: Yoan Vallet <ext.sopra.yvallet@grandlyon.com> Date: Mon, 8 Jun 2020 10:22:27 +0200 Subject: [PATCH] Prevent faillure if no consent on load curve --- src/index.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/index.js b/src/index.js index 1964943..4346495 100644 --- a/src/index.js +++ b/src/index.js @@ -106,7 +106,6 @@ async function start(fields, cozyParameters, doRetry = true) { fields.access_token = body.attributes.oauth.access_token return start(fields, cozyParameters, false) } - log('error', `Error during authentication: ${err.message}`) throw errors.VENDOR_DOWN } else { @@ -161,8 +160,19 @@ async function getLoadData(token, usagePointID) { Authorization: 'Bearer ' + token } } - const response = await rp(dataRequest) - return response + try { + const response = await rp(dataRequest) + return response + } catch (err) { + if (err.statusCode === 404 || err.code === 404) { + log('warning', 'caught an 404 error') + log('warning', err.message) + log('warning', err) + return null + } else { + throw err + } + } } /** -- GitLab