sailthru / sailthru-node-client

Sailthru Node.js client
http://docs.sailthru.com
MIT License
17 stars 15 forks source link

SyntaxError: Unexpected token A #4

Closed malkomalko closed 12 years ago

malkomalko commented 12 years ago

It looks like every once in a while, the response being sent over in is some weird message and it tries to JSON.parse this weird message without a try/catch so it will bomb.

Stacktrace:

Sun Apr 29 2012 05:02:14 GMT-0400 (EDT) -> SyntaxError: Unexpected token A at Object.parse (native) at IncomingMessage. (/home/deploy/app/source/node_modules/sailthru-client/lib/sailthru.js:78:32) at IncomingMessage.emit (events.js:88:20) at HTTPParser.onMessageComplete (http.js:137:23) at CleartextStream.ondata (http.js:1147:24) at CleartextStream._push (tls.js:367:27) at SecurePair.cycle (tls.js:688:20) at EncryptedStream.write (tls.js:122:13) at Socket.ondata (stream.js:38:26) at Socket.emit (events.js:67:17

infynyxx commented 12 years ago

I think, that happens when you get 500 - Internal Server Error which happens to origin from Pound Load Balancer breaking JSON parser.

I guess, I will just add try-catch when using JSON.parse. Even though, it's kind of anti-pattern, it should work.