Search code examples
javascriptgoogle-chromepromisebluebirdsuperagent

chrome 53 not catching unhandled rejected promises


I'm using chrome 53 on development and a certain API call returns a rejected bluebird promise. Although I have error handlers in my code, the rejected promise is not caught, just consoled.

the API call:

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

and the error handlers:

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);
});

Works on Firefox 31 and Chromium 35


Solution

  • Thanks to @JaromandaX 's comment, I figured that I forgot to override the native promises with bluebird ones.