Skip to content

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

Function: recoverIf()

Call Signature

ts
function recoverIf<TError, TResult>(predicate, errorConverter): (error) => TResult;

If failed, maps the error to another value if it matches the given type guard.

Can be applied on the .catch() method of a Promise.

Type Parameters

Type Parameter
TError
TResult

Parameters

ParameterType
predicate(error) => error is TError
errorConverter(error) => TResult

Returns

ts
(error): TResult;

Parameters

ParameterType
errorunknown

Returns

TResult

Call Signature

ts
function recoverIf<TResult>(predicate, errorConverter): (error) => TResult;

If failed, maps the error to another value if it matches the given predicate.

Can be applied on the .catch() method of a Promise.

Type Parameters

Type Parameter
TResult

Parameters

ParameterType
predicate(error) => boolean
errorConverter(error) => TResult

Returns

ts
(error): TResult;

Parameters

ParameterType
errorunknown

Returns

TResult