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/TimeoutError.md.

TimeoutError es-toolkit

An error class representing an operation that has timed out.

const error = new TimeoutError(message);

Usage

new TimeoutError(message?)

An error class used when an operation's time limit has been exceeded. It is thrown when operations like timeout or withTimeout have timed out.

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

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

// Create an error with a custom message.
throw new TimeoutError('API request has timed out');
// Error message: 'API request has timed out'

An example of using it with timeout.

import { timeout, TimeoutError } from 'es-toolkit';

async function fetchWithTimeout(url: string) {
  try {
    const response = await Promise.race([fetch(url), timeout(3000)]);
    return response;
  } catch (error) {
    if (error instanceof TimeoutError) {
      console.log('Request has timed out');
    }
    throw error;
  }
}

// Throws TimeoutError if it takes more than 3 seconds
await fetchWithTimeout('https://example.com/api/slow');

Parameters

messagestringoptional

The error message. Defaults to 'The operation was timed out'.

Returns

Returns an error instance representing a timed out operation. It inherits from Error and the name property is 'TimeoutError'.

TimeoutError
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.