我正在使用 NestJs 并遇到一个问题。我只是无法在 WebSocket 网关中抛出异常。
一切按照this doc page .
我尝试过包含
@UseFilters(new BaseWsExceptionFilter())
但是...没有帮助。
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.');
}
}
我有这样的smt...
/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)
最佳答案
由于早期版本中的错误,它无法工作。请将您的依赖项更新到最新版本,例如使用 npm update
或 yarn Upgrade
。
关于javascript - WebSocketGateway 中的 WsException 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58000638/