-
-
Notifications
You must be signed in to change notification settings - Fork 7.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Not throwing the exception/error when using ws adapter websocket #9056
Comments
Any updates on this issue. Please provide the solution or alternative way to handle this. |
Hi, it's working but needs more testing. If you find a bug, please report it.
EDIT: New method, working and tested:
|
this answer worked for me better https://stackoverflow.com/a/62507382/11109259 @wilywork methods to find the acknowledgement methods fail sometimes |
My ack callback (3rd Argument) is undefined, has anybody experienced this too? |
realy, ACK is not always the last parameter, so I made this correction, my current code:
|
The provided solutions so far work only with 'socket-io'. I am also looking for a solution for 'ws'. |
Okay, so after a bit of trial and error, I discovered a method that works with the @Catch(TestException)
export class TestWsExceptionFilter implements ExceptionFilter {
catch(exception: TestException, host: ArgumentsHost) {
const client = host.switchToWs().getClient<WebSocket>();
const response = {
error: exception.message,
exception,
};
client.send(JSON.stringify(response));
}
} |
Is there an existing issue for this?
Current behavior
When I am trying to throw the exception/error on conditional basis on websocket it is not sending any handshake to the client.
here is the simple code
I have just investigated why not throwing error found issue in this file
https://github.com/nestjs/nest/blob/master/packages/websockets/exceptions/base-ws-exception-filter.ts#L33
https://github.com/nestjs/nest/blob/master/packages/websockets/exceptions/base-ws-exception-filter.ts#L41
For ws - websocket adapter emit method is not working.
Minimum reproduction code
https://codesandbox.io/s/admiring-hugle-o8wqf?file=/src/Event/event.gateway.ts
Steps to reproduce
No response
Expected behavior
Should throw the handshake error or close the web socket.
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
No response
Packages versions
Node.js version
No response
In which operating systems have you tested?
Other
No response
The text was updated successfully, but these errors were encountered: