node-red-contrib-power-saver
node-red-contrib-power-saver copied to clipboard
Node-Red crashes if Elvia returns invalid json
This is a serious bug, causing Node-Red to crash everytime the node runs.
This is the log from Node-Rd in Home Assistant:
10 Nov 10:58:16 - [info] Updated flows 10 Nov 10:58:16 - [info] Starting modified flows 10 Nov 10:58:16 - [info] Started modified flows 10 Nov 10:58:25 - [red] Uncaught Exception: 10 Nov 10:58:25 - [error] FetchError: invalid json response body at https://elvia.azure-api.net/grid-tariff/digin/api/1.0/tariffquery?TariffKey=private_flatrate_house&StartTime=2022-11-09T23:00:00&EndTime=2022-11-10T23:00:00 reason: Unexpected end of JSON input at /config/node-red/node_modules/node-fetch/lib/index.js:273:32 at processTicksAndRejections (node:internal/process/task_queues:96:5) [10:58:26] WARNING: Node-RED crashed, halting add-on [10:58:26] INFO: Node-RED stopped, restarting... s6-rc: info: service legacy-services: stopping [10:58:26] INFO: Node-RED stopped, restarting... s6-svwait: fatal: supervisor died s6-rc: info: service legacy-services successfully stopped s6-rc: info: service legacy-cont-init: stopping s6-rc: info: service legacy-cont-init successfully stopped s6-rc: info: service fix-attrs: stopping s6-rc: info: service fix-attrs successfully stopped s6-rc: info: service s6rc-oneshot-runner: stopping s6-rc: info: service s6rc-oneshot-runner successfully stopped
this is the respons when using Elvias test API for the same url:
Response status 500 Internal Server Error Response latency 17830 ms
Yes, Elvia has a server issue but the node is not recovering from it. This causes Node-Red to go down.
What version are you using?
I'm using
- Node "Add Elvia Grid Tariff", node-red-contrib-power-saver v. 3.6.2
- node-red Current version: 13.5.2
- Node-Red Companion v1.1.2
- Home Assistant 2022.11.2 Supervisor 2022.10.2 Operating System 9.3 Frontend 20221108.0 - latest
Hmm. I thought I had fixed that. Vould hou provide a flow with a minimum to reproduce it?
Hmm. I thought I had fixed that. Vould hou provide a flow with a minimum to reproduce it?
Try to change elvia url to something that gives you a 500 internal error. Elvia reported the error as solved. Edit: https://elvia.portal.azure-api.net/Issues
I just checked the Elvia code quickly (so I might have missed something), if server returns 500 then there is no Json returned. Wouldn't this line then fail? https://github.com/ottopaulsen/node-red-contrib-power-saver/blob/main/src/elvia/elvia-api.js#L41
You're right, it will fail.
I think this is at least better in version 4.0.0. Please try.
Thanks, i see you are checking for 500 error explicitly, shouldn't there be an else check on line 40 to catch all errors, and prevent node-red crash? Or at least check if json is valid before exception is thrown?
Btw, great work on all the nodes you have created! Keep it up:)
A fix is ready for next release.
I think this issue could be closed :)