luc-ass / homebridge-evohome

Homebridge plugin for Honeywell Evohome
29 stars 16 forks source link

Crash: Unexpected token T in JSON at position 0 #10

Closed rooi closed 6 years ago

rooi commented 7 years ago

Hi,

Thanks for making this plugin. I just received a crash with the following log. For now I'll just post it as an issue, perhaps I can try to solve it later and issue a PR.

SyntaxError: Unexpected token T in JSON at position 0 at Object.parse (native) at Request._callback (/usr/local/lib/node_modules/homebridge-evohome/lib/evohome.js:181:26) at Request.self.callback (/usr/local/lib/node_modules/homebridge-evohome/node_modules/request/request.js:121:22) at emitTwo (events.js:106:13) at Request.emit (events.js:191:7) at Request. (/usr/local/lib/node_modules/homebridge-evohome/node_modules/request/request.js:978:14) at emitOne (events.js:101:20) at Request.emit (events.js:188:7) at IncomingMessage. (/usr/local/lib/node_modules/homebridge-evohome/node_modules/request/request.js:929:12) at emitNone (events.js:91:20) at IncomingMessage.emit (events.js:185:7) at endReadableNT (_stream_readable.js:974:12) at _combinedTickCallback (internal/process/next_tick.js:74:11) at process._tickCallback (internal/process/next_tick.js:98:9)

luc-ass commented 7 years ago

Did you find a solution? I have never had this problem before...

rooi commented 7 years ago

I've had it twice and since I added a try/catch it did not crash any longer. Not sure if this was the fix, or that the event didn't occur after that.

I changed the following. Perhaps you can review it or should I send a PR?

function(err, response) { if(err) { deferred.reject(err); } else { var json; try { json = JSON.parse(response.body); } catch(ex) {
console.error(ex); console.error(response.body); console.error(response); deferred.reject(ex); } if(json) { deferred.resolve(json); } }

luc-ass commented 7 years ago

If you have it fixed I'd love to accept your pull request :)