I am using ws for websocket in my node application. I want to simulate the possible errors that the server can get. I don't want to modify the server code, so I am trying to do that from the client side.
When I am emitting an error from the client side, that error was coming to client error handler, not going to the server. How can I send the error to the server(not as a message, as error event), so that I can test the error handlers there?
This is what I tried,
var WebSocket = require('ws')
var server = //url
var myClient = new WebSocket(server);
myClient.on('open', function() {
setTimeout(function() {
sendError(myClient);
}, 5000);
});
myClient.on('error', clientErrorHandler(){
//client error handler
//This is being executed when emitting error
})
myClient.on('close', closeS(){
//to clear some data
})
function sendError(client){
client.emit('error', new Error('ECONNRESET'));
}
When the error emitted , clientErrorHandler got executed. It is not going to server. But I want this to be handled by server's error handler. How can that be done?
via RaR
No comments:
Post a Comment