QNimbus/node-red-contrib-openhab-v2

Uncaught Exception in openhab-v2.js:261:37

Closed this issue · 2 comments

When openhab responses status with 503 no body will be send, so the following code will fail.

var body = JSON.parse(response.body);

The response object looks like this:

{"statusCode":503,"body":"<html>\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\"/>\n<title>Error 503 Jersey is not ready yet!</title>\n</head>\n<body><h2>HTTP ERROR 503</h2>\n<p>Problem accessing /rest/items/Mower_Activated. Reason:\n<pre> Jersey is not ready yet!</pre></p><hr><a href=\"http://eclipse.org/jetty\">Powered by Jetty:// 9.4.11.v20180605</a><hr/>\n\n</body>\n</html>\n","headers":{"connection":"close","cache-control":"must-revalidate,no-cache,no-store","content-type":"text/html;charset=iso-8859-1","content-length":"373","server":"Jetty(9.4.11.v20180605)"},"request":{"uri":{"protocol":"http:","slashes":true,"auth":"user:pass","host":"localhost:8080","port":"8080","hostname":"localhost","hash":null,"search":null,"query":null,"pathname":"/rest/items/itemname/state","path":"/rest/items/itemname/state","href":"http://user:pass@localhost:8080/rest/items/itemname/state"},"method":"PUT","headers":{"authorization":"Basic blablablablabla=","content-length":19}}}

log file content

3 Apr 12:13:56 - [red] Uncaught Exception:
3 Apr 12:13:56 - SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at Request._callback (/home/user/.node-red/node_modules/node-red-contrib-openhab-v2/openhab-v2.js:261:37)
    at Request.self.callback (/home/user/.node-red/node_modules/request/request.js:185:22)
    at Request.emit (events.js:189:13)
    at Request.<anonymous> (/home/user/.node-red/node_modules/request/request.js:1161:10)
    at Request.emit (events.js:189:13)
    at IncomingMessage.<anonymous> (/home/user/.node-red/node_modules/request/request.js:1083:12)
    at Object.onceWrapper (events.js:277:13)
    at IncomingMessage.emit (events.js:194:15)
    at endReadableNT (_stream_readable.js:1125:12)
    at process._tickCallback (internal/process/next_tick.js:63:19)
nodered.service: Main process exited, code=exited, status=1/FAILURE
nodered.service: Unit entered failed state.
nodered.service: Failed with result 'exit-code'.
nodered.service: Service hold-off time over, scheduling restart.
Stopped Node-RED graphical event wiring tool.

I can't even start node-red anymore because of this (similar) exception.

22 Apr 21:26:02 - [info] Flows starten
22 Apr 21:26:02 - [info] [openhab-v2-controller:OpenHAB2-Server] Controller attempting to connect to: http://10.10.1.155:8080/rest/events/?topics=smarthome/items
22 Apr 21:26:02 - [info] Flows gestartet
22 Apr 21:26:02 - [info] [openhab-v2-controller:OpenHAB2-Server] Requesting URI http://10.10.1.155:8080/rest/items/ with method GET
22 Apr 21:26:02 - [red] Uncaught Exception:
22 Apr 21:26:02 - SyntaxError: Unexpected token < in JSON at position 0
    at JSON.parse (<anonymous>)
    at Request._callback (/home/tim/.node-red/node_modules/node-red-contrib-openhab-v2/openhab-v2.js:261:37)
    at Request.self.callback (/home/tim/.node-red/node_modules/request/request.js:185:22)
    at emitTwo (events.js:126:13)
    at Request.emit (events.js:214:7)
    at Request.<anonymous> (/home/tim/.node-red/node_modules/request/request.js:1161:10)
    at emitOne (events.js:116:13)
    at Request.emit (events.js:211:7)
    at IncomingMessage.<anonymous> (/home/tim/.node-red/node_modules/request/request.js:1083:12)
    at Object.onceWrapper (events.js:313:30)
nodered.service: Main process exited, code=exited, status=1/FAILURE
nodered.service: Failed with result 'exit-code'.

I changed ".node-red/node_modules/node-red-contrib-openhab-v2/openhab-v2.js:262:23" from "210" to "400", because response.body contained " .... HTTP/400 ...".
Node-Red starts again, workflows are looking fine. I'm sure this is just a dirty hack, but at least all the flows are up and running again.