AbortErrorA class for representing interruption errors. Extends the built-in Error class and adds interrupt-specific properties.
import { AbortError } from 'saborter/errors';
name
'AbortError' (const string)message
stringtype
'cancelled' | 'aborted'abortedtimestamp
numberDate.now()reason?
anytruecause?
Errorstack
stringmetadata?
anytrueinitiator
'timeout' | 'user' | 'system'userWhen 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.
new AbortError(message, options?)
Parameters:
message: string - Text error message.options?: Object
type?: 'cancelled' | 'aborted' (Default is aborted) - Abort type.reason?: any - Additional reason for interruption.metadata?: any - Interrupt-related data. The best way to pass any data inside the error.const error = new AbortError('The operation was interrupted');
console.error(error.message); // 'The operation was interrupted'
console.error(error.type); // 'aborted'
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' }
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
TimeoutErrorA class for representing timeout interrupt errors. Extends the built-in Error class and adds properties specific to timeout interrupts.
import { TimeoutError } from 'saborter/errors';
name
'TimeoutError' (const string)message
stringtimestamp
numberDate.now()ms?
numbertruereason?
anytruemetadata?
anytruenew TimeoutError(message, options?)
Parameters:
message: string - Text error message.options?: Object
ms?: number - Time in milliseconds after which interrupts should be started.reason?: any - A field storing the error reason.metadata?: any - Interrupt-related data. The best way to pass any data inside the error.// 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 }
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