Skip to content

API reference / @backpack/error-handling / promises / onFailureIfInstanceOf

Function: onFailureIfInstanceOf()

ts
function onFailureIfInstanceOf<TError>(errorClass, errorConsumer): (error) => never;

Executes the given callback if failed, if the error is an instance of the class provided, letting the original error pass through.

Can be applied on .catch() method of a Promise to introduce a side effect, such as logging.

Type Parameters

Type Parameter
TError

Parameters

ParameterType
errorClassClass<TError>
errorConsumer(error) => void

Returns

ts
(error): never;

Parameters

ParameterType
errorunknown

Returns

never