Skip to content

Overview / catchError

catchError()

catchError<T, E>(promise, options?): Promise<[undefined, T] | [InstanceType<E>]>

Catches errors from a promise.

Type Parameters

Type Parameter
T
E extends (...args) => Error

Parameters

ParameterTypeDescription
promisePromise<T>The promise to handle.
options?objectAdditional options for handling the promise.
options.errorsToCatch?E[]An optional array of error constructors to catch.
options.logMessage?stringAn optional message to log when an error occurs.

Returns

Promise<[undefined, T] | [InstanceType<E>]>

A tuple with either the error or the result of the promise.

Throws

Will rethrow the error if it is not in the errorsToCatch array.

Released under the GPL-3.0 License.