stack

Home > @infiniteobjects/core-library-web > Async > tapCatch

Async.tapCatch() method

Tap into a promise chain without affecting its value or state. Use this in a .catch() method.

Signature:

static tapCatch<ErrorType = unknown>(tapHandler: (error: ErrorType) => unknown): (error: ErrorType) => Promise<never>;

Parameters

Parameter Type Description
tapHandler (error: ErrorType) => unknown Any return value is ignored. Exceptions thrown in tapHandler are relayed back to the original promise chain. If tapHandler returns a Promise, it will be awaited before passing through the original value.

Returns:

(error: ErrorType) => Promise<never>

A [thunk](https://en.wikipedia.org/wiki/Thunk) that returns a Promise.

Example

import { Promises } from '@infiniteobjects/core-library';

Promise.resolve(() => doSomething())
  .catch(Async.tapCatch(console.error)) // prints any errors
  .then(handleSuccess)
  .catch(handleError);