Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assumption that payload data is always JSON #7

Open
nivertech opened this issue Oct 16, 2014 · 1 comment
Open

Assumption that payload data is always JSON #7

nivertech opened this issue Oct 16, 2014 · 1 comment

Comments

@nivertech
Copy link

There is assumption that message payload is JSON:
https://github.com/abhishiv/pusher-node-client/blob/master/lib/pusher-node-client.coffee#L117

Error I getting is:

SyntaxError: Unexpected number
  at Object.parse (native)
  at PusherClient.recieveMessage (/home/xxx/local/node/lib/node_modules/pusher-node-client/lib/pusher-node-client.js:175:51)
  at PusherClient.recieveMessage (/home/xx/local/node/lib/node_modules/pusher-node-client/lib/pusher-node-client.js:6:61)
  at WebSocketConnection.<anonymous> (/home/xxx/local/node/lib/node_modules/pusher-node-client/lib/pusher-node-client.js:140:24)
  at WebSocketConnection.emit (events.js:95:17)
  at WebSocketConnection.processFrame (/home/xxx/local/node/lib/node_modules/pusher-node-client/node_modules/websocket/lib/WebSocketConnection.js:356:26)
  at WebSocketConnection.handleSocketData (/home/xxx/local/node/lib/node_modules/pusher-node-client/node_modules/websocket/lib/WebSocketConnection.js:205:14)
  at CleartextStream.emit (events.js:95:17)
  at CleartextStream.<anonymous> (_stream_readable.js:764:14)
  at CleartextStream.emit (events.js:92:17)
  at emitReadable_ (_stream_readable.js:426:10)
  at _stream_readable.js:419:7
  at process._tickCallback (node.js:419:13)

In my case payload is just a string, not a valid JSON.
The payload is a strings like "00012345|0006789".
The error is:

JSON.parse("00012345|0006789")
SyntaxError: Unexpected number
    at Object.parse (native)
    at repl:1:7
    at REPLServer.self.eval (repl.js:110:21)
    at Interface.<anonymous> (repl.js:239:12)
    at Interface.emit (events.js:95:17)
    at Interface._onLine (readline.js:202:10)
    at Interface._line (readline.js:531:8)
    at Interface._ttyWrite (readline.js:760:14)
    at ReadStream.onkeypress (readline.js:99:10)
    at ReadStream.emit (events.js:98:17)

One solution is to add additional argument to channel.subscribe function, which will be indicating that there is no need to treat message payloads as JSON.

@abhishiv
Copy link
Owner

PR welcomed for this topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants