由Promise提供的NestJS UnhandledPromiseRejection警告

时间:2019-09-30 16:41:36

标签: node.js angular

在Swagger和Postman中运行Get方法时,出现以下错误消息:

  

(节点:35014)UnhandledPromiseRejectionWarning:TypeError:无法读取null的属性“错误”       在HttpErrorFilter.catch(/Users/mapoferl/Documents/develop/BuergermeisterApp/backendnest/src/shared/http-error.filter.ts:28:31)       在ExceptionsHandler.invokeCustomFilters(/Users/mapoferl/Documents/develop/BuergermeisterApp/backendnest/node_modules/@nestjs/core/exceptions/exceptions-handler.js:31:26)       在ExceptionsHandler.next(/Users/mapoferl/Documents/develop/BuergermeisterApp/backendnest/node_modules/@nestjs/core/exceptions/exceptions-handler.js:12:18)       在/Users/mapoferl/Documents/develop/BuergermeisterApp/backendnest/node_modules/@nestjs/core/router/router-proxy.js:12:35       在process._tickCallback(内部/进程/next_tick.js:68:7)   (节点:35014)UnhandledPromiseRejectionWarning:未处理的承诺拒绝。引发此错误的原因可能是抛出了一个没有catch块的异步函数,或者是拒绝了一个.catch()无法处理的承诺。 (拒绝ID:1)   (节点:35014)[DEP0018] DeprecationWarning:已弃用未处理的承诺拒绝。将来,未处理的承诺拒绝将以非零退出代码终止Node.js进程。

d.service.ts

public async getCorporateDesignByDistrictName(name: string): Promise<CorporateDesign> {
    const district: District = await this.districtRepository.createQueryBuilder('district')
        .leftJoinAndSelect('district.mandant', 'mandant')
        .leftJoinAndSelect('district.corporateDesign', 'corporateDesign')
        .where('district.name = :name')
        .andWhere('district.isDeleted = :isDeleted')
        .setParameters({
            name: name,
            isDeleted: false
        })
        .getOne();
    return district.corporateDesign;
}

d.controller.ts

@UseGuards(AuthGuard)
@Get(':name')
public async getCorporateDesignByDistrictName(@Param('name') name: string): Promise<CorporateDesign> {
    return this.districtService.getCorporateDesignByDistrictName(name);
}

我正在使用angular 8和nest.js

0 个答案:

没有答案