-
Notifications
You must be signed in to change notification settings - Fork 0
handler recover
Raphael Pigulla edited this page Apr 22, 2022
·
1 revision
Suppress the current error and return a value instead.
This handler allows you to ignore errors and return a value instead.
The following options are supported.
-
callback: (error, ...parameters) => T | Promise<T>
(mandatory)
The callback must return a value (or Promise) compatible with the return value of the wrapped function. The callback is invoked with the same context as the wrapped function (unless you use an arrow function). -
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). -
onCallbackError: CallbackErrorAction
(optional, defaults toTHROW_WRAPPED
)
This option controls how errors thrown by the callback are handled.-
THROW_WRAPPED
: The error is wrapped in anMapError
. This is the default. -
THROW
: The error is thrown as-is. -
THROW_TRIGGER
: The error is ignored and the triggering error is thrown instead.
-
class Foo {
@HandleError({
action: HandlerAction.RECOVER,
callback: () => 42
})
public async doSomething(): Promise<number> {
// if something goes wrong, return 42 instead
}
}