New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

catch-to

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

catch-to

Catch errors and declaratively map them to other errors or values.

  • 0.4.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
decreased by-50%
Maintainers
1
Weekly downloads
 
Created
Source

catch-to

Catch errors and declaratively map them to other errors or values.

This is useful when you do not wish to expose the specific errors your system uses to describe its internal state, and instead want to respond with more general, human-like errors.

Example

const Boom = require('boom')
const toErrors = require('catch-to')(Boom.badImplementation)

const login = require('./login')
const {
  UnauthorizedLoginError,
  AccountLockedError,
  TooManyLoginsError,
  MissingAuthenticityTokenError
} = require('./errors')

login('username', 'password')
  .catch(
    toErrors([
      {
        on: [ UnauthorizedLoginError, MissingAuthenticityTokenError ],
        toError: err => Boom.unauthorized(err)
      },
      {
        on: TooManyLoginsError
        toError: Boom.badRequest()
      },
      {
        on: AccountLockedError,
        toError: Boom.locked()
      }
    ])
  )

API

CreateCatchToSignature: (fallbackError?: ToErrorSignature, defaultLog?: LogSignature): CatchToSignature

CatchToSignature: (errorCategories?: ErrorCategory|Array<ErrorCategory>, log?: LogSignature): CatchSignature

CatchSignature: (error: Error): Error|any

Types

ErrorCategory: Array<{ on: Error|Array<Error>|ErrorPredicateSignature, toError?: Error|ToErrorSignature, toValue?: any|ToValueSignature }>
ErrorPredicateSignature: (error: Error): boolean
ToErrorSignature: (error: Error): Error
ToValueSignature: (error: Error): any
LogSignature: (message?: string): void

Install

yarn add catch-to

Keywords

FAQs

Package last updated on 10 Apr 2017

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc