Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an event listener for unhandledrejections? #3

Open
ejdaly opened this issue Jan 8, 2020 · 1 comment
Open

Add an event listener for unhandledrejections? #3

ejdaly opened this issue Jan 8, 2020 · 1 comment

Comments

@ejdaly
Copy link

ejdaly commented Jan 8, 2020

Hi,

Thanks for the library.

I can see there is an event listener to catch global "error" events, but not on global "unhandledrejection" events.

E.g if my worker code does something like below, it won't get handled by the registerError callback.

const test = function() {
  return new Promise(function(resolve, reject) {
    setTimeout(() => {
      reject(new Error("test error"))
      }, 5000);
    })
}

test();

Would it make sense to add a global listener for that, e.g. could just "re-throw" that error

self.addEventListener("unhandledrejection", function (e) {
  e.preventDefault();
  throw e.reason;
});
@dumbmatter
Copy link
Owner

Yeah, it probably does make sense to handle "unhandledrejection" events similar to "error" events. I'm not sure when I'll get around to adding it, but probably eventually. Or, PR welcome :)

I wonder if there are any other events that should be handled similarly too..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants