Issue
I'm playing with NestJs and stuck with one problem. I just can`t throw an exception in WebSocket gateway.
Everything is according to this doc page.
I have tried to include
@UseFilters(new BaseWsExceptionFilter())
But... didn`t help.
import {
SubscribeMessage,
WebSocketGateway,
WebSocketServer, WsException,
} from '@nestjs/websockets';
import { Client, Server } from 'socket.io';
@WebSocketGateway()
export class EventsGateway {
@WebSocketServer()
server: Server;
@SubscribeMessage('exception')
exception(client: Client, data: number) {
throw new WsException('Invalid credentials.');
}
}
And I had smt like this...
/home/innistry/Projects/nest-likbez/node_modules/rxjs/internal/util/hostReportError.js:4
[0] setTimeout(function () { throw err; }, 0);
[0] ^
[0]
[0] TypeError: host.setType is not a function
[0] at WsProxy.handleError (/home/innistry/Projects/nest-likbez/node_modules/@nestjs/websockets/context/ws-proxy.js:26:14)
[0] at EventsGateway.<anonymous> (/home/innistry/Projects/nest-likbez/node_modules/@nestjs/websockets/context/ws-proxy.js:20:22)
[0] at process._tickCallback (internal/process/next_tick.js:68:7)
Solution
It does not work because of a bug in an earlier version. Please update your dependencies to the latest version, e.g., with npm update
or yarn upgrade
.
Answered By - Kim Kern
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.