bounce

API v3.0.x

Installation:

npm: npm install @hapi/bounce

yarn: yarn add @hapi/bounce

rethrow(err, types, [options])

Throws the error passed if it matches any of the specified rules where:

  • err - the error.
  • type - a single item or an array of items of:
    • An error constructor (e.g. SyntaxError).
    • 'system' - matches any languange native error or node assertions.
    • 'boom' - matches boom errors.
    • an object where each property is compared with the error and must match the error property value. All the properties in the object must match the error but do not need to include all the error properties.
  • options - optional object where:
    • decorate - an object which is assigned to the err, copying the properties onto the error.
    • override - an error used to override err when err matches. If used with decorate, the override object is modified.
    • return - if true, the error is returned instead of thrown. Defaults to false.

ignore(err, types, [options])

The opposite action of rethrow(). Ignores any errors matching the specified types. Any error not matching is thrown after applying the options.

background(operation, [action], [types], [options])

Awaits for the value to resolve in the background and then apply either the rethrow() or ignore() actions where:

  • operation - a function, promise, or value that is awaited on inside a try...catch and any error thrown processed by the action rule.
  • action - one of 'rethrow' or 'ignore'. Defaults to 'rethrow'.
  • types - same as the types argument passed to rethrow() or ignore(). Defaults to 'system'.
  • options - same as the options argument passed to rethrow() or ignore().

isBoom(err)

Returns true when err is a boom error.

isError(err)

Returns true when err is an error.

isSystem(err)

Return true when err is one of:

  • EvalError
  • RangeError
  • ReferenceError
  • SyntaxError
  • TypeError
  • URIError
  • Node's AssertionError
clipboard