【发布时间】:2023-01-03 02:45:47
【问题描述】:
我已将我的应用程序从 Nest.js v8 更新到 Nest.js v9,现在每次抛出错误时应用程序都会退出。
以前,只是返回 HTTPException。但是现在每次服务器终止时我都会收到此错误:
`TypeError: Cannot read properties of undefined (reading 'preSerialization')`
系统:
节点:18
以下软件包已更新:
@nestjs/common: 9.2.1
@nestjs/core: 9.2.1
@nestjs/microservices: 9.2.1
@nestjs/platform-express: 9.2.1
@nestjs/platform-fastify: 9.2.1
@nestjs/platform-socket.io: 9.2.1
@nestjs/swagger: 9.2.1
@nestjs/websockets: 9.2.1
该错误仅在我在中间件中抛出异常时发生,否则它会起作用。
@Injectable()
export class AuthMiddleware implements NestMiddleware {
async use(req: Request, res: Response, next: NextFunction): Promise<NextFunction> {
if (req.method === 'OPTIONS') {
next();
}
if (!req.headers.authorization) {
throw new HttpException('No credentials set', HttpStatus.UNAUTHORIZED);
}
const token = req.headers.authorization;
const claims = await authClient.verify(token);
....
next();
}
}
有没有人遇到过这个问题?我觉得跟fastify有关系,但是还没找到解决方法。
我也尝试过其他版本,但从 v9 开始它不起作用。它也不适用于其他节点版本。
【问题讨论】:
-
你设法解决这个问题了吗?升级到v9后有同样的问题
-
不,不幸的是没有
标签: node.js nestjs nestjs-fastify