saborter

Error documentation

AbortError

A class for representing interruption errors. Extends the built-in Error class and adds interrupt-specific properties.

πŸ”§ API

Import

import { AbortError } from 'saborter/errors';

Properties

name

message

type

timestamp

reason?

cause?

stack

metadata?

initiator

When the error is triggered by a timeout, it means that automatic request cancellation was configured and the cancellation was successful.

When the error is triggered by the user, it means that the user interrupted the request by calling the abort() method.

When the error is triggered by the system, it means that you caught an error canceling a previous request.

Constructor

new AbortError(message, options?)

Parameters:

🎯 Usage Examples

Basic Usage

const error = new AbortError('The operation was interrupted');

console.error(error.message); // 'The operation was interrupted'
console.error(error.type); // 'aborted'

Creation with type and metadata

const error = new AbortError('Request cancelled', {
  type: 'cancelled',
  metadata: { requestId: '123', userId: 'user_456' }
});

console.error(error.type); // 'cancelled'
console.error(error.metadata); // { requestId: '123', userId: 'user_456' }

Active additional debug information in the error stack

import { AbortError } from 'saborter/errors';
import { setDebugErrorStackMode } from 'saborter/dev';

// Activating the extended debug stack information
// The error stack is expanded exclusively for Saborter errors
setDebugErrorStackMode(true);

const abortError = new AbortError('Aborted');

// In the console you will see an expanded stack with the full list of data for this error
console.log(abortError); // or abortError.stack

TimeoutError

A class for representing timeout interrupt errors. Extends the built-in Error class and adds properties specific to timeout interrupts.

πŸ”§ API

Import

import { TimeoutError } from 'saborter/errors';

Properties

name

message

timestamp

ms?

reason?

metadata?

Constructor

new TimeoutError(message, options?)

Parameters:

🎯 Usage Examples

Basic Usage

// Basic Usage
const error = new TimeoutError('Request timed out');

// With Options
const error = new TimeoutError('The operation exceeded its execution time', {
  ms: 3000,
  reason: 'any reason',
  metadata: { userId: 1 }
});

// Accessing Properties
console.log(error.timestamp); // 1641234567890
console.log(error.ms); // 3000
console.log(error.reason); // 'any reason'
console.log(error.metadata); //  { userId: 1 }

Active additional debug information in the error stack

import { TimeoutError } from 'saborter/errors';
import { setDebugErrorStackMode } from 'saborter/dev';

// Activating the extended debug stack information
// The error stack is expanded exclusively for Saborter errors
setDebugErrorStackMode(true);

const timeoutError = new TimeoutError('Request timed out');

// In the console you will see an expanded stack with the full list of data for this error
console.log(timeoutError); // or abortError.stack