altangent / ccxws

WebSocket client for 38 cryptocurrency exchanges
MIT License
619 stars 186 forks source link

Error parsing upbit json #61

Closed vkrot closed 5 years ago

vkrot commented 5 years ago

Exchange Upbit

Subscription type Trades

Describe the bug Error parsing upbit json response, process exited on error. This happened after a few successful days of consuming upbit trades socket. I think node process should not stop on such kinds of errors?

info: connected to wss://api.upbit.com/websocket/v1
undefined:1
x�e�Mo�0
        ����-JB[5�Cڄh�=���6 !��>[[U}�_��?^���������P��v�۱‚w���n(xJ!2ɥL�?�2ړA0.c��<���Ƌ4/8���,eAFW����ZdAx�͝�<g+�;$k�G��o��
                                                                                                                         Nڔ2���ꦟ\wY���
                                                                                                                                      -��Q�!�S�cdN�v��w�QD�N ��խ��^yܜ��S?���b�
^

SyntaxError: Unexpected token x in JSON at position 0
    at JSON.parse (<anonymous>)
    at UpbitClient._onMessage (/usr/src/app/node_modules/ccxws/src/exchanges/upbit-client.js:72:17)
    at emitOne (events.js:116:13)
    at SmartWss.emit (events.js:211:7)
    at WebSocket._wss.on.msg (/usr/src/app/node_modules/ccxws/src/smart-wss.js:70:43)
    at emitOne (events.js:116:13)
    at WebSocket.emit (events.js:211:7)
    at Receiver.receiverOnMessage (/usr/src/app/node_modules/ws/lib/websocket.js:720:20)
    at emitOne (events.js:116:13)
    at Receiver.emit (events.js:211:7)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! vkrot@0.1.0 start: `node ws.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the vkrot@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2019-04-18T03_04_14_107Z-debug.log

To Reproduce Steps to reproduce the behavior: No idea, this fixed after restart and happened only once.

Expected behavior Log error, but do not stop proccess

bmancini55 commented 5 years ago

Thanks for submitting the issue!

The library should handle parsing errors better than it does. The original intent was that we wanted hard failures so we could easily catch problems. A better solution is to catch these exceptions and emit an error event.

This pushes error handling onto the consumer of the library. If the consumer wants to ignore / log errors they attach an error event handler. The default behavior when no error handler exists will terminate the application as it does now.

vkrot commented 5 years ago

I see, thanks a lot for quick response. I never used js before, so didn't know that.

bmancini55 commented 5 years ago

No problem. Reopening the issue. Sorry I was unclear with my previous message and was just thinking out loud.

At present, CCXWS clients do not emit the error event. At current, it will always result in a hard failure.

We still need to add this functionality into the library.

bmancini55 commented 5 years ago

Addressed in PR #95