我正在做一个 Nestjs REST API 项目,我必须在其中添加 swagger。我以这个 repo 为例:https://github.com/nestjs/nest/tree/master/sample/11-swagger
但是我收到了这个错误:
UnhandledPromiseRejectionWarning:类型错误:无法解构“未定义”或“空”的属性“原型(prototype)”
还有这个:
UnhandledPromiseRejectionWarning:未处理的 promise 拒绝。此错误源于在没有 catch block 的情况下在异步函数内部抛出或拒绝未使用 .catch() 处理的 promise 。
项目在这里:
https://github.com/strdr4605/nestjs-rest-api/blob/swagger/src/main.ts
最佳答案
我在 Swagger 尝试解析事件 Controller 内的 Kafka 消息的有效负载时遇到问题,因此我添加了 ApiExcludeEndpoint
以排除消息处理程序
@ApiExcludeEndpoint()
@EventPattern('topic', Transport.KAFKA)
public async handleEvent(@Payload() message: EventDto): Promise<void> {
// ...
关于javascript - Nestjs Swagger UnhandledPromiseRejectionWarning : TypeError: Cannot destructure property `prototype` of 'undefined' or 'null' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53758553/