Skip to content

Include message type and message id in WebSocket onError response #48

@kestivvi

Description

@kestivvi

In the onError method of the WebSocket handler, there is a TODO comment stating that the message type and message id should be included in the response if possible. This is important information for the client to know in order to properly handle the error.

I suggest adding this functionality to the onError method so that the message type and message id are included in the response when available. This will improve the error handling and debugging process for both the client and server.

@Override
public void onError(WebSocket webSocket, Exception e) {
// TODO: Message type and message id in the response should be included if possible
if (e.getClass().isAssignableFrom(CustomException.class)) {
CustomException exception = (CustomException) e;
Log.ERROR(exception.toString());
webSocket.send(exception.toJsonResponse());
} else {
Log.ERROR("Server error: " + e.getMessage());
ErrorResponse response = new ErrorResponse(Result.ERROR, e.getMessage());
webSocket.send(response.ToJson());
}
}

Solving this issue would involve modifying the CustomException class to include the message type and message id, and then modifying the onError method in the WebSocket handler to extract this information from the exception and include it in the response.

To modify the CustomException class, you would need to add instance variables for the message type and message id, and modify the constructor to accept these values as parameters. You would also need to modify the toJsonResponse method to include these values in the JSON response.

Once the CustomException class has been modified, you would need to modify the onError method in the WebSocket handler to extract the message type and message id from the exception (if they are present) and include them in the response. This would involve modifying the if block that handles CustomException objects to extract the message type and message id from the exception and include them in the response.

Overall, this would involve modifying the CustomException class and the onError method in the WebSocket handler.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions