Build an object to be used to cancel context API call.

function buildCancelTokenSource(): {cancel: () => void; token: CancelToken};

Return value

The function returns an object with the following properties

cancelFunctionFunction to call to cancel the request.
tokenCancelTokenToken to use as a parameter to the function to make it cancellable.


Cancelling a function invocation does not guarantee the action will not be executed on Front. It is merely a way to abort the Promise returned by the function.

import {buildCancelTokenSource, isCancelError} from '@frontapp/plugin-sdk';

const source = buildCancelTokenSource();
// Do not wait more than 500ms for the list of teammates.
setTimeout(() => source.cancel(), 500);

try {
  const list = await Front.listTeammates(undefined, source.token);
} catch (error) {
  if (isCancelError(error))
    return; // Do nothing.
  throw error;