node-red-contrib / node-red-contrib-renault-ze

node-red extension to fetch the status from your renault connected car
Apache License 2.0
19 stars 6 forks source link

Uncaught Exception: invalid json response body #83

Closed PatrickM2201 closed 10 months ago

PatrickM2201 commented 1 year ago

I am running the node (Version 1.4.1) on a node-red Version v3.0.2. Since some time an uncaught exception of the this node causes node-red to crash.

In the syslog I find the following entries (account entry behind /accounts/ I replaced with xxx:

Jan 25 08:44:08 Node-Red Node-RED[400378]: 25 Jan 08:44:08 - [red] Uncaught Exception: Jan 25 08:44:08 Node-Red Node-RED[400378]: 25 Jan 08:44:08 - [error] FetchError: invalid json response body at https://api-wired-prod-1-euw1.wrd-aws.com/commerce/v1/accounts/xxxxxxxxxxxxxxxx/kamereon/kca/car-adapter/v2/cars/VF1AG000568538007/battery-status?country=DE reason: Unexpected token < in JSON at position 0 Jan 25 08:44:08 Node-Red Node-RED[400378]: at /root/.node-red/node_modules/node-fetch/lib/index.js:273:32 Jan 25 08:44:08 Node-Red Node-RED[400378]: at runMicrotasks () Jan 25 08:44:08 Node-Red Node-RED[400378]: at processTicksAndRejections (node:internal/process/task_queues:96:5) Jan 25 08:44:08 Node-Red systemd[1]: nodered.service: Main process exited, code=exited, status=1/FAILURE Jan 25 08:44:08 Node-Red systemd[1]: nodered.service: Failed with result 'exit-code'.

After the restart data is provided again without any problems. I did not recognized any cause of the invalid json response (e.g. loss of internet connection).

If you need further information, I will try to collect them.

fraz3alpha commented 1 year ago

I have come across the same class of error numerous times at work, and the fact it gets a < means that the server has responded with HTML instead of JSON, and died parsing it. If I was to guess, the server probably had an internal error and gave a error 500 type page. As you say this was transitory and worked again later, the server probably was fine at other times - so it could have been excess load on the server, maintenance, or any number of things that meant it didn't work as intended.

Sounds like the return code of the page should be checked before parsing, or at least catching the exception and stopping

konne commented 10 months ago

I will maybe pick it up in the next versions