Use Custom Error Classes for Validation

This commit is contained in:
2026-07-23 07:56:50 +00:00
parent 7cb9a29e77
commit 205fb18785
3 changed files with 112 additions and 40 deletions
+40
View File
@@ -20,3 +20,43 @@ export class ExponentialBackoffStoppedRetriesError extends Error {
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}`);
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}`);
this.name = 'ExponentialBackoffNumberOutOfBoundsError';
}
}
/**
* Error thrown when an exponential backoff option is an invalid infinite integer
*/
export class ExponentialBackoffInvalidInfiniteIntegerError extends Error {
constructor(option: string) {
super(`Exponential backoff option "${option}" is invalid. Must be a finite number`);
this.name = 'ExponentialBackoffInvalidInfiniteIntegerError';
}
}
/**
* Error thrown when an exponential backoff option is not an integer
*/
export class ExponentialBackoffNonIntegerError extends Error {
constructor(option: string) {
super(`Exponential backoff option "${option}" is invalid. Must be an integer`);
this.name = 'ExponentialBackoffNonIntegerError';
}
}