chrome 53 未捕获未处理的拒绝承诺

chrome 53 not catching unhandled rejected promises

我正在使用 chrome 53 开发和某个 API 调用 returns 拒绝的 bluebird 承诺。尽管我的代码中有错误处理程序,但没有捕获到被拒绝的承诺,只是得到了安慰。

API 调用:

function call() {
    return new Promise((resolve, reject) => {
        superagent
            .get('some url')
            .end((err, res) => {
                if(err) {
                    return reject(err);
                }
                resolve(res);
            });
    });
}

和错误处理程序:

window.onerror = ((message, filename, lineno, colno, error) => {
    const {unhandledErrors} = this.state;

    if(!error) {
        return;
    }

    error.timestamp = moment().format('YYYY-MM-DD HH:mm:ss');

    //handling error in React
    this.setState({
        unhandledErrors: updateUnhandledErrors(unhandledErrors, error)
    });

    console.error(error);
});

window.onunhandledrejection = (({reason}) => {
    const {unhandledErrors} = this.state;
    const error = reason;
    error.timestamp = moment().format('YYYY-MM-DD HH:mm:ss');

    //handling error in React
    this.setState({
        unhandledErrors: updateUnhandledErrors(unhandledErrors, error)
    });

    console.error(error);
});

// bluebird handler
window.addEventListener('unhandledrejection', e => {
    e.preventDefault();
    const {unhandledErrors} = this.state;

    const error = e.detail.reason;
    error.timestamp = moment().format('YYYY-MM-DD HH:mm:ss');

    //handling error in React
    this.setState({
        unhandledErrors: updateUnhandledErrors(unhandledErrors, error)
    });

    console.error(error);
});

适用于 Firefox 31 和 Chromium 35

感谢@JaromandaX 的评论,我发现我忘记用 bluebird 覆盖原生 promise。