Description
Current behaviour
In server.js file, generateId
errors are handled as the below:
this.generateId(req, function (err, id) {
if (err) {
sendErrorMessage(req, req.res, Server.errors.BAD_REQUEST);
return;
}
...
}
Because of generateId
method can be overwritten by the user, it should be throw the error what the user sent.
My proposal:
this.generateId(req, function (err, id) {
if (err) {
sendErrorMessage(req, req.res, err);
return;
}
...
}
I could not decide this is the correct way to handle errors or not. Because, the user function might throws an error that designed by the user.
However, the error turns into a BAD_REQUEST
error in the end.
On the other hand this is a part of socket.io
and socket.io-client-java
modules do not handle the error of BAD_REQUEST
on any method (if I'm right).
For instance I throw different error codes on generateId
method on different cases. Then I handle this error on client side (like invalidate_auth_token).
I use a workaround for this for now. I send error codes as socketId then I check the socketId value in a socket middleware. If socketId value is one of the error codes, then disconnect the connection and send the error code to the client.