mdottavio / ya-lifx

:bulb: - Yet Another LIFX JS client
MIT License
8 stars 1 forks source link

crashes node with json parse error when lifx api returns a html webpage #7

Closed Bluebie closed 6 years ago

Bluebie commented 7 years ago

https://github.com/mdottavio/ya-lifx/blob/master/src/requestHandler.js#L42

undefined:1
<!DOCTYPE html>
^

SyntaxError: Unexpected token < in JSON at position 0
    at Object.parse (native)
    at Request._callback (./node_modules/ya-lifx/src/requestHandler.js:35:21)
    at Request.self.callback (./node_modules/request/request.js:186:22)
    at emitTwo (events.js:106:13)
    at Request.emit (events.js:191:7)
    at Request.<anonymous> (./node_modules/request/request.js:1081:10)
    at emitOne (events.js:96:13)
    at Request.emit (events.js:188:7)
    at IncomingMessage.<anonymous> (./node_modules/request/request.js:1001:12)
    at IncomingMessage.g (events.js:291:16)

ya-lifx needs to be able to catch this error, since apparently LIFX returns webpages sometimes.

mdottavio commented 6 years ago

Hope the new version prevent this issue.