Skip to content

Instantly share code, notes, and snippets.

@cevek
Created September 19, 2018 12:33
Show Gist options
  • Save cevek/a72bb77b75715bc7a9cf59789d4b84ac to your computer and use it in GitHub Desktop.
Save cevek/a72bb77b75715bc7a9cf59789d4b84ac to your computer and use it in GitHub Desktop.
Devtools enhancement: Pause on exceptions inside promise.then or catch without checked caught in exceptions
function create(fn, name) {
if (fn === undefined) return;
const callback = data => {
let ret;
new Promise(() => (ret = fn(data)));
return ret;
};
callback.displayName = name;
return callback;
}
Promise.prototype.nativeThen = Promise.prototype.then;
Promise.prototype.nativeCatch = Promise.prototype.catch;
Promise.prototype.then = function (onFullFilled, onRejected) {
return this.nativeThen(create(onFullFilled, 'onFullFilled'), create(onRejected, 'onRejected'));
};
Promise.prototype.catch = function (onRejected) {
return this.nativeCatch(create(onRejected, 'onRejected'));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment