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
Thanks to @JaromandaX 's comment, I figured that I forgot to override the native promises with bluebird
ones.