93 lines
3.1 KiB
TypeScript
93 lines
3.1 KiB
TypeScript
/**
|
|
* Error thrown when a response body is null
|
|
*/
|
|
export class ResponseBodyNullError extends Error {
|
|
constructor() {
|
|
super('Response body is null');
|
|
this.name = 'ResponseBodyNullError';
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Error thrown when an HTTP error occurs
|
|
*/
|
|
export class HTTPError extends Error {
|
|
constructor(status: number, message: string) {
|
|
super(`HTTP error! Status: ${status} - ${message}`);
|
|
this.name = 'HTTPError';
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Error thrown when the maximum number of retries is hit in an exponential backoff
|
|
*/
|
|
export class ExponentialBackoffMaxRetriesHitError extends Error {
|
|
constructor(errors: Array<Error>) {
|
|
super('Exponential backoff: Max retries hit', { cause: errors });
|
|
this.name = 'ExponentialBackoffMaxRetriesHitError';
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Error thrown when the exponential backoff retries are stopped
|
|
*/
|
|
export class ExponentialBackoffStoppedRetriesError extends Error {
|
|
constructor(reason: unknown) {
|
|
// Convert the reason to an error if it is not an error
|
|
const reasonError = reason instanceof Error ? reason : new Error(`${reason}`);
|
|
|
|
super(`Exponential backoff was aborted: "${reasonError.message}"`, { cause: reasonError });
|
|
this.name = 'ExponentialBackoffStoppedRetriesError';
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Error thrown when an exponential backoff option is too small
|
|
*/
|
|
export class ExponentialBackoffNumberTooSmallError extends Error {
|
|
constructor(option: string, value: number, min: number) {
|
|
super(`Exponential backoff option "${option}" is too small. Must be at least ${min}. Received value: ${value}`);
|
|
this.name = 'ExponentialBackoffNumberTooSmallError';
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Error thrown when an exponential backoff option is out of bounds
|
|
*/
|
|
export class ExponentialBackoffNumberOutOfBoundsError extends Error {
|
|
constructor(option: string, value: number, min: number, max: number) {
|
|
super(`Exponential backoff option "${option}" is out of bounds. Must be between ${min} and ${max}. Received value: ${value}`);
|
|
this.name = 'ExponentialBackoffNumberOutOfBoundsError';
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Error thrown when an exponential backoff option is an invalid infinite integer
|
|
*/
|
|
export class ExponentialBackoffNumberNotFiniteError extends Error {
|
|
constructor(option: string, value: number) {
|
|
super(`Exponential backoff option "${option}" is invalid. Must be a finite number. Received value: ${value}`);
|
|
this.name = 'ExponentialBackoffNumberNotFiniteError';
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Error thrown when an exponential backoff option is not an integer
|
|
*/
|
|
export class ExponentialBackoffNonIntegerError extends Error {
|
|
constructor(option: string, value: number) {
|
|
super(`Exponential backoff option "${option}" is invalid. Must be an integer. Received value: ${value}`);
|
|
this.name = 'ExponentialBackoffNonIntegerError';
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Error thrown when a waitFor timeout is reached
|
|
*/
|
|
export class WaitForTimeoutError extends Error {
|
|
constructor(type: string) {
|
|
super(`Timeout waiting for event "${type}"`);
|
|
this.name = 'WaitForTimeoutError';
|
|
}
|
|
}
|