A class for representing interruption errors. Extends the built-in Error class and adds interrupt-specific properties.
import { AbortError } from 'saborter/errors';name
- Type:
'AbortError'(const string) - Description: Interrupt error name.
message
- Type:
string - Description: Interrupt error message.
type
- Type:
'cancelled' | 'aborted' - Description: Abort type.
- Default:
aborted
timestamp
- Type:
number - Description: The timestamp in milliseconds when the error was created.
- Default:
Date.now()
reason?
- Type:
any - Description: Additional reason or data associated with the interrupt.
- Optional:
true
cause?
- Type:
Error - Description: A field containing additional error information indicating the reason for the current error.
stack
- Type:
string - Description: The default stack field is 'Error' without extended information. To enable extended information, see here.
metadata?
- Type:
any - Description: Interrupt-related data. The best way to pass any data inside the error. This field will not be overridden in any way.
- Optional:
true
initiator
- Type:
'timeout' | 'user' | 'system' - Description: A field with the name of the error initiator.
- Default:
user
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.
new AbortError(message, options?)Parameters:
message: string- Text error message.options?: Objecttype?: 'cancelled' | 'aborted'(Default isaborted) - 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.stackA 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
- Type:
'TimeoutError'(const string) - Description: Timeout error name.
message
- Type:
string - Description: Timeout error message.
timestamp
- Type:
number - Description: The timestamp in milliseconds when the error was created.
- Default:
Date.now()
ms?
- Type:
number - Description: A field displaying the time in milliseconds after which the request was interrupted.
- Optional:
true
reason?
- Type:
any - Description: Additional reason or data associated with the interrupt.
- Optional:
true
metadata?
- Type:
any - Description: Interrupt-related data. The best way to pass any data inside the error. This field will not be overridden in any way.
- Optional:
true
new TimeoutError(message, options?)Parameters:
message: string- Text error message.options?: Objectms?: 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