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 = const toErrors = BoombadImplementation const login = const UnauthorizedLoginError AccountLockedError TooManyLoginsError MissingAuthenticityTokenError } =
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