ericelliott / ericelliott/speculation
Util for error branching?
Open
- Dominant language
- JavaScript
- Stars
- 198
- Forks
- 6
- PR merge metrics
- No merged PRs in 30d
Description
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:
```js
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.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.