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

Util for error branching? #3

Open
ericelliott opened this issue Jan 21, 2017 · 0 comments
Open

Util for error branching? #3

ericelliott opened this issue Jan 21, 2017 · 0 comments

Comments

@ericelliott
Copy link
Owner

ericelliott commented Jan 21, 2017

People think they need separate channels for handling cancellations, but a simple error branching utility could be a better solution. Here's a trivial example:

const handleErrors = (
  fn,
  onCancel = () => {}
) => e => {
  (/Cancelled/.test(e.message)) ?
    onCancel(e) : fn(e);
};

const handler = handleErrors(
  e => console.log(`Not cancelled: ${ e }`),
  c => console.log(`Cancelled: ${ c }`)
);

A handleErrors() utility could be fleshed out to handle custom error predicates, and to handle any number of different kinds of errors.

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

1 participant