From 9c7109dc18bb43e4e6e96a554b96590ba2700153 Mon Sep 17 00:00:00 2001
From: Yoan VALLET <ext.sopra.yvallet@grandlyon.com>
Date: Mon, 8 Jun 2020 10:24:17 +0200
Subject: [PATCH] publish: Prevent faillure if no consent on load curve

generated from commit e6e8ce69c0f9108df554a9d75baa1f8ea9f1d3a7
---
 index.js | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/index.js b/index.js
index dc0abf3..22905f0 100644
--- a/index.js
+++ b/index.js
@@ -196,7 +196,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 {
@@ -251,8 +250,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