New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

swallow-errors

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

swallow-errors

Swallow function errors.

latest
Source
npmnpm
Version
0.0.2
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

swallow-errors

Build Status Coverage Npm Version MIT License

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.

FAQs

Package last updated on 26 Nov 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts