BaseExceptionFilter provider for WebSocket using WS doesn't send error messages to client #11433
Closed
3 of 15 tasks
Labels
needs triage
This issue has not been looked into
Is there an existing issue for this?
Current behavior
``I have spent pretty extensive time looking for an answer to this situation and the very few instances I found where it was mentioned failed to address the primary issue or provide a clear answer.
When running a WebSocket gateway using the WS platform and using the BaseWsExceptionFilter to catch validation errors thrown by the ValidationPipe provider applied to the gateway, the error is logged to the console on the server side but nothing is sent to the client.
I believe this may be due to the fact that the BaseWsExceptionFilter uses
client.emit('exception', message)
which, I believe, is Socket.io specific.Gateway code:
Error captured on server:
Minimum reproduction code
https://github.com/dieeisenefaust/janus-ws
Steps to reproduce
npm run build
npm run start
either use something like Browser WebSocket Client (a Chrome extensions) and/or a HTML client like 'clienttest.html' in the root of the repo provided.
The validation pipe is enforcing the IsNotEmpty class-validator decorators in the create-timespan.dto.ts file. So any message should include userId, location, job and task.
Sending a payload without userId will trigger an exception.
The exception will only show in console.log within your code editor running the server.
Expected behavior
Expect an error to be returned to the client.
Package
@nestjs/common
@nestjs/core
@nestjs/microservices
@nestjs/platform-express
@nestjs/platform-fastify
@nestjs/platform-socket.io
@nestjs/platform-ws
@nestjs/testing
@nestjs/websockets
Other package
No response
NestJS version
9.3.0
Packages versions
Node.js version
18.14.2
In which operating systems have you tested?
Other
No response
The text was updated successfully, but these errors were encountered: