feat: ws simple setup only

This commit is contained in:
SauravDhakal
2026-04-12 21:50:46 +05:45
parent 2f01adeade
commit 4686e0abbc
13 changed files with 334 additions and 23 deletions

View File

@@ -0,0 +1,29 @@
import { Catch, ArgumentsHost } from '@nestjs/common';
import { BaseWsExceptionFilter, WsException } from '@nestjs/websockets';
@Catch()
export class WsValidationExceptionFilter extends BaseWsExceptionFilter {
catch(exception: unknown, host: ArgumentsHost) {
const client = host.switchToWs().getClient();
if (exception instanceof WsException) {
client.emit('exception', {
status: 'error',
message: exception.getError(),
});
return;
}
// Handle ValidationPipe errors (they come as plain objects, not WsException)
if (
Array.isArray((exception as any)?.response?.message)
) {
client.emit('exception', {
status: 'error',
message: (exception as any).response.message,
});
return;
}
super.catch(exception, host);
}
}