> For AI agents: the complete documentation index is available at https://massaman.dev/llms.txt, the full documentation bundle is available at https://massaman.dev/llms-full.txt.

# AbortError es-toolkit

An error class representing an aborted or canceled operation.

```typescript
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](https://massaman.dev/reference/function/debounce.md) or [delay](https://massaman.dev/reference/promise/delay.md) are canceled with an `AbortSignal`.

```typescript
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.

```typescript
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'`.

```typescript
AbortError
```


Source: es-toolkit

Re-exported verbatim from [`es-toolkit`](https://es-toolkit.dev/reference/error/AbortError.html). Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.
