Skip to content

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

Function: recoverIfInstanceOf()

ts
function recoverIfInstanceOf<TError, TResult>(errorClass, errorConverter): (e) => TResult;

If failed, maps the error to a value if it is an instance of the provided error class.

Can be applied on the .catch() method of a Promise to recover from specific errors.

Type Parameters

Type Parameter
TError
TResult

Parameters

ParameterType
errorClassClass<TError>
errorConverter(error) => TResult

Returns

ts
(e): TResult;

Parameters

ParameterType
eunknown

Returns

TResult