Skip to content

handler pass through

Raphael Pigulla edited this page Apr 22, 2022 · 1 revision

PASS_THROUGH

Synopsis

Immediately throw the current error.

Description

This handler short-circuits the handler chain and causes the current error to be thrown immediately.

A common use case it to ignore errors that you want to bubble up explicitly.

Options

The following options are supported.

  • scope: Class<Error> (optional)
    Limit the handler to exceptions of the given class (or any subclass thereof).
  • predicate: (error, ...parameters) => boolean | Promise<boolean> (optional)
    Dynamically skip invocation of the handler depending on the error thrown or any of the wrapped method's parameters. The predicate is invoked with the same context as the wrapped function (unless you use an arrow function).

Example

class Foo {
    @HandleError(
        {
            action: HandlerAction.PASS_THROUGH,
            scope: SyntaxError,
        },
        {
            // This handler will never run for SyntaxErrors
            action: HandlerAction.MAP,
            callback: error => new FooError({ cause: error }),
        }
    )
    public async doSomething(): Promise<void> {
        // SyntaxErrors will bubble up directly, everything else will be wrapped in a FooError
    }
}