admin管理员组文章数量:1334335
I'm using the WebSocket library ws for node.js and I'm trying to simulate an error event on the server that would trigger my error handling code:
ws.on('error', function(e) {
console.log("error occured");
});
I tried referencing an undefined variable in the on('message') event but that just crashed the whole server and the 'error' event never fired.
Can anyone tell me how to simulate a ws error event on the server?
Thank you!
I'm using the WebSocket library ws for node.js and I'm trying to simulate an error event on the server that would trigger my error handling code:
ws.on('error', function(e) {
console.log("error occured");
});
I tried referencing an undefined variable in the on('message') event but that just crashed the whole server and the 'error' event never fired.
Can anyone tell me how to simulate a ws error event on the server?
Thank you!
Share Improve this question asked Mar 26, 2016 at 22:43 Jared SpragueJared Sprague 2494 silver badges13 bronze badges 2-
4
Couldn't you just emit it manually (e.g.
ws.emit('error', new Error('foo'))
) or pull theerror
event handler out and call it directly? – mscdex Commented Mar 26, 2016 at 23:00 - 1 ws.emit('error') worked, thanks! – Jared Sprague Commented Mar 26, 2016 at 23:10
1 Answer
Reset to default 8Manually emitting the event should work (ws.emit('error', new Error('foo'))
) as well as calling the error
event handler directly (by pulling it out and naming it).
本文标签: javascriptWebSocket ws how to simulate error eventStack Overflow
版权声明:本文标题:javascript - WebSocket ws how to simulate error event? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742268433a2443846.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论