Skip to content

Commit

Permalink
improved error handling for web requests
Browse files Browse the repository at this point in the history
  • Loading branch information
chpro committed Sep 17, 2024
1 parent a13425b commit 7f7d62b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/control.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ function shiftAvailableEnergy(statusValues) {
*/
function isWaterTemperatureToHigh(statusValues, maxWaterTemperature, maxWaterTemperatureDelta) {
if (statusValues.currentWaterTemperature === null) {
return false;
return true;
}

// turn off if maxWaterTemperature is reached
Expand Down
21 changes: 13 additions & 8 deletions app/influxdataprovider.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,20 @@ function transformWattpilotResponse(response) {
return retVal;
}

function useNull(error) {
console.log(new Date(), "Could not get response", error);
return {data: null};
}

function getCurrentStatusValues(switchOn, callback) {
axios.all([
axios.get(INFLUX_GRID_USAGE_LAST, {headers: INFLUX_REQUEST_HEADER}),
axios.get(INFLUX_GRID_USAGE_MEAN, {headers: INFLUX_REQUEST_HEADER}),
axios.get(INFLUX_WATER_TEMPERATURE_LAST, {headers: INFLUX_REQUEST_HEADER}),
axios.get(INFLUX_BOILER_STATUS, {headers: INFLUX_REQUEST_HEADER}),
axios.get(INFLUX_BATTERY_CHARGE_LAST, {headers: INFLUX_REQUEST_HEADER}),
axios.get(INVERTER_POWER_FLOW),
axios.get(CONFIG.wattpilotMetricsUrl, {transformResponse: transformWattpilotResponse})
axios.get(INFLUX_GRID_USAGE_LAST, {headers: INFLUX_REQUEST_HEADER}).catch(useNull),
axios.get(INFLUX_GRID_USAGE_MEAN, {headers: INFLUX_REQUEST_HEADER}).catch(useNull),
axios.get(INFLUX_WATER_TEMPERATURE_LAST, {headers: INFLUX_REQUEST_HEADER}).catch(useNull),
axios.get(INFLUX_BOILER_STATUS, {headers: INFLUX_REQUEST_HEADER}).catch(useNull),
axios.get(INFLUX_BATTERY_CHARGE_LAST, {headers: INFLUX_REQUEST_HEADER}).catch(useNull),
axios.get(INVERTER_POWER_FLOW).catch(useNull),
axios.get(CONFIG.wattpilotMetricsUrl, {transformResponse: transformWattpilotResponse}).catch(useNull)
]).then(axios.spread((gridLastRes, gridMeanRes, waterTemperatureRes, boilerStatusRes, batteryChargeRes, inverterPowerFlowRes, wattpilotRes) => {
callback(getStatusValues(
getValue(gridMeanRes.data),
Expand All @@ -58,7 +63,7 @@ function getCurrentStatusValues(switchOn, callback) {
switchOn,
getValue(boilerStatusRes.data),
getValue(batteryChargeRes.data),
inverterPowerFlowRes.data.site,
inverterPowerFlowRes.data === null ? null : inverterPowerFlowRes.data.site,
wattpilotRes.data));
})).catch(err => {
console.log(new Date(), err);
Expand Down

0 comments on commit 7f7d62b

Please sign in to comment.