diff --git a/src/index.js b/src/index.js index 6c065ec2eca71623d30c43db5181fb514de3ab26..4b1f599b7d7b472fab1b240e8c57d2adb107fe84 100644 --- a/src/index.js +++ b/src/index.js @@ -308,23 +308,12 @@ function format(response) { log('info', 'filtered size is: ' + data.length) - try { - return data.map(value => { - const time = DateTime.fromISO(value.DateReleve) - const processedLoad = value.ValeurIndex - refValue.ValeurIndex - - if (processedLoad < 0) { - const errorMessage = `Processing load error for day ${time.toLocaleString( - DateTime.DATE_SHORT - )}, value is: ${processedLoad}` - log('debug', errorMessage) - throw errors.VENDOR_DOWN - } - - // Change the index reference value - refValue = value - - return { + return data.reduce((loads, value) => { + const processedLoad = value.ValeurIndex - refValue.ValeurIndex + const time = DateTime.fromISO(value.DateReleve) + // Check that load is positive and that water meter has not changed + if (processedLoad >= 0 && value.TypeAgregat !== 'D') { + loads.push({ load: processedLoad, year: time.year, month: time.month, @@ -332,15 +321,20 @@ function format(response) { hour: 0, minute: 0, type: value.TypeAgregat, - } - }) - } catch (error) { - log('debug', error.message) - Sentry.captureException(error, { - tags: { - section: 'format', - }, - }) - throw error - } + }) + } else { + Sentry.captureMessage('New water meter or invalid load value', { + extra: { + processedLoad, + value, + }, + tags: { + section: 'format', + }, + }) + } + // Change the index reference value + refValue = value + return loads + }, []) }