Antoni Zwolski
02/20/2024, 9:40 PMwebSocket("/chat/{user_id}") {
val userId = "call.getUserId()"
webSocketConnectionManager.addSession(userId, this)
try {
for (frame in incoming) {
if(frame is Frame.Text){
val message = gson.fromJson(frame.readText(), MessageDto::class.java)
val response = chatService.sendMessage(userId, message.roomId, message.content)
}
}
} finally {
webSocketConnectionManager.removeSession(userId)
}
}
Lets assume that gson throw a exception, cause client send data in invalid structure. How to return some nice response, without using try catch, is it possible to do it somehow with status pages? Pipelines?Aleksei Tirman [JB]
02/21/2024, 7:48 AMchatService.sendMessage
function operates by sending WebSocket frames, then, unfortunately, it cannot utilize pipeline mechanisms similar to those available for HTTP in Ktor, as WebSocket communications do not support such features.