Let's say I have the following WebSocketGateway in NestJS
@WebSocketGateway()
export class MyWsGateway {
@SubscribeMessage('my-event')
@UserFilters(new MyWsExceptionFilter())
create(@MessageBody() body: any) {
throw new WsException('Forced error');
}
}
At this point I want to customize the response to the client when an error occurs so I have implemented my own WsExceptionFilter based on NestJS official code (note this code is simplified):
@Catch(WsException)
export class MyWsExceptionFilter extends BaseWsExceptionFilter {
handleError<TClient extends { emit: Function }>(
client: TClient,
exception: WsException
) {
const message = {status: 'error', message: exception.getError()};
client.emit('here-is-where-i-would-like-to-set-the-event-name', message);
}
}
As you can see on the implementation of BaseWsExceptionFilter the response of the error is emited through event 'exception'. This is not valid for my case, though.
After long time searching on the Internet and surfing in NestJS's code, I haven't been able to find a way to get/know the input event name where the error was thrown.
Any ideas?