cb不是函数-使用Winston处理未处理的Promise Rejection时

cb不是函数-使用Winston处理未处理的Promise Rejection时

当我运行此代码来处理使用Winston处理的Promise拒绝时,获取cb不是一个功能。在控制台中,它显示了确切的错误,但它存储的cb不是函数。

<form *ngFor="let project of projectsArr; let i = index;">
        <mat-form-field>
           <textarea matInput class="md-textarea form-control dc-text-field__input mui-textfield mui-textfield--float-label" rows="3" cols="40" name="info{{i}}" [(ngModel)]="projectsArr[i].info"></textarea>
        </mat-form-field>

         <mat-card-actions>
           <button class="mat-button" name="submitButton" #submitButton id="button{{i}}" type="submit" mat-raised-button color="primary" [disabled]="!projectsArr[i].info" (click)="saveInfo(info,i)">
            <span class="mat-button__label">Save Now</span>
           </button>
        </mat-card-actions>
</form>
  

在端口3000上监听...错误:未处理的拒绝......... !!!   错误:未处理的拒绝...... !!!       在对象。 (F:\ Node js课程[FreeCoursesOnline.Me] CodeWithmosh-完整的Node.js课程\ 9-猫鼬-建模   Connected Data \ 9.7- Project- Build the Rentals之间的关系   API \ after \ vidly \ index.js:36:26)       在Module._compile(internal / modules / cjs / loader.js:956:30)       在Object.Module._extensions..js(内部/模块/cjs/loader.js:973:10)       在Module.load(internal / modules / cjs / loader.js:812:32)       在Function.Module._load(内部/模块/cjs/loader.js:724:14)       在Function.Module.runmain(内部/模块/cjs/loader.js:1025:10)       在internal / main / run_main_module.js:17:11

higays1 回答:cb不是函数-使用Winston处理未处理的Promise Rejection时

免责声明:我不使用Winston。

您正在传递ex作为期望函数的第二个参数。在您给定的代码中,ex不是函数,而是Error或类似的实例。

您应该执行以下代码段。

// NOTE: this code is not tested
process.on("unhandledRejection",(ex) => {
     winston.error(ex.message,() => { // this should be your callback
         // do something inside your callback function
     });
     process.exit(1);
});
// NOTE: this code is not tested

或者,如果您知道TypeScript,请阅读以下内容:https://github.com/winstonjs/winston/blob/master/index.d.ts#L60

或者这个适合您的情况:https://github.com/winstonjs/winston/blob/master/index.d.ts#L68

本文链接:https://www.f2er.com/3161369.html

大家都在问