0.0.2 • Published 2 years ago
swallow-errors v0.0.2
swallow-errors
Ignore function errors.
Install
yarn add swallow-errors
Usage
import {wrap, execute} from 'swallow-errors'
const foo = wrap(() => {
throw new Error('oops!')
})
// Returns a function will never throw errors
execute(() => {
throw new Error('oops!')
})
// Execute the function and ignore possible errors
API
wrap(originalFunction, ignore?)
Type: function
Returns a function that will ignore errors passed ignore
test.
originalFunction
Type: function
The function to wrap
ignore
Type: function
The error test function, if it's omitted, all errors will be ignored.
To ignore specific errors, return true
const foo = wrap(
function () {
throw new Error('foo')
},
(error) => error?.message === 'bar',
)
foo()
// Throws a error with message `foo`
execute(originalFunction, ignore?)
Execute the wrapped function without arguments.