I'm trying to use a "bad input exception filter" to catch errors and return them to the client. I have both websockets and http endpoints throughout my monorepo, on one application I have both.
The issue I'm having, I don't want to use two separate exception filters for WS & HTTP and until now I was relying on nestjs defining either the request or the socket context to tap into that and either return the error back to the websocket or returning the error via http res.send.
But it turns out they're both defined even when there's no websockets within the application at all, no adapter registered, nothing.
Exception handler:
const req: IRequest = host.switchToHttp().getRequest();
const res: Response = host.switchToHttp().getResponse();
const socket: ISocket = host.switchToWs().getClient();
if (req && res) {
// returning req res
}
if (socket) {
// emitting error on socket
Is there a way to either:
- prevent this
- tap into another value from the context to know where to return the error to
Thank you.