Hello! I’m creating a WebSocket endpoint using Tapir, Fs2, and http4s and I’ve noticed that when the websocket receives a request that doesn’t match what is expected it will close the websocket connection. eg. My endpoint is Endpoint[Unit, Long, String, Pipe[IO, Request, Response], Any with Fs2Streams[IO] with WebSockets]
, if the requests being sent to the websocket doesn’t match the model for Request it will close the connection. Is this the intended behavior? What if I wanted to keep the connection open and return an error message?
Yes, that’s the way it’s currently designed. The problem is that if there’s a decode error, we don’t have any way of reacting to that.
A work-around would be to use the “raw” web socket variant: webSocketBodyRaw
, and handle any decode errors on that level. Of course, this way you loose the docs, so that’s far from ideal.
Maybe we should add some optional error handlers, which would have the option of sending an error message, or closing the WS? Something like a DecodeFailureHandler
, but for web sockets… but that would require some design work. Maybe you could create an issue for that?
1 Like