feat: ws simple setup only
This commit is contained in:
29
common/exceptions/websocket.ts
Normal file
29
common/exceptions/websocket.ts
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user