Promise reject() causes “Uncaught (in promise)” warning

前端 未结 3 539
鱼传尺愫
鱼传尺愫 2020-12-03 00:27

Once a promise reject() callback is called, a warning message \"Uncaught (in promise)\" appears in the Chrome console. I can\'t wrap my head around the

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-03 01:08

    I've solved that problem in my project, it's a large enterprise one. My team is too lazy to write empty catch hundreds of times.

    Promise.prototype.then = function (onFulfilled, onRejected) {
        return baseThen.call(this, (x: any) => {
            if (onFulfilled)
                onFulfilled(x);
        }, (x: any) => {
            if (onRejected)
                onRejected(x);
        });
    };
    

提交回复
热议问题