For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /reference/error/AbortError.md.

AbortError es-toolkit

An error class representing an aborted or canceled operation.

const error = new AbortError(message);

Usage

new AbortError(message?)

An error class used when an operation is aborted or canceled. It is thrown when operations like debounce or delay are canceled with an AbortSignal.

import { AbortError } from 'es-toolkit/error';

// Create an error with the default message.
throw new AbortError();
// Error message: 'The operation was aborted'

// Create an error with a custom message.
throw new AbortError('File upload was canceled');
// Error message: 'File upload was canceled'

An example of using it with AbortSignal.

import { AbortError, delay } from 'es-toolkit';

async function fetchData(signal: AbortSignal) {
  try {
    await delay(1000, { signal });
    return 'Data loaded';
  } catch (error) {
    if (error instanceof AbortError) {
      console.log('Operation was canceled');
    }
    throw error;
  }
}

const controller = new AbortController();
controller.abort(); // Cancel operation
await fetchData(controller.signal); // Throws AbortError

Parameters

messagestringoptional

The error message. Defaults to 'The operation was aborted'.

Returns

Returns an error instance representing an aborted operation. It inherits from Error and the name property is 'AbortError'.

AbortError
Source: es-toolkit

Re-exported verbatim from es-toolkit. Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.