|
| 1 | +// error.ts |
| 2 | + |
| 3 | +/** |
| 4 | + * Base class representing retryable errors. |
| 5 | + * Inherits from JavaScript's built-in Error class. |
| 6 | + * Suitable for errors where the system can attempt to retry the operation. |
| 7 | + */ |
| 8 | +export class RetryableError extends Error { |
| 9 | + constructor(message: string) { |
| 10 | + super(message); |
| 11 | + this.name = 'RetryableError'; |
| 12 | + Object.setPrototypeOf(this, new.target.prototype); // Fixes the inheritance chain for instanceof checks |
| 13 | + } |
| 14 | +} |
| 15 | + |
| 16 | +/** |
| 17 | + * Base class representing non-retryable errors. |
| 18 | + * Inherits from JavaScript's built-in Error class. |
| 19 | + * Suitable for errors where the system should not attempt to retry the operation. |
| 20 | + */ |
| 21 | +export class NonRetryableError extends Error { |
| 22 | + constructor(message: string) { |
| 23 | + super(message); |
| 24 | + this.name = 'NonRetryableError'; |
| 25 | + Object.setPrototypeOf(this, new.target.prototype); // Fixes the inheritance chain for instanceof checks |
| 26 | + } |
| 27 | +} |
| 28 | + |
| 29 | +// Below are specific error classes inheriting from the appropriate base classes |
| 30 | + |
| 31 | +/** |
| 32 | + * Error: File Not Found. |
| 33 | + * Indicates that a required file could not be found during file operations. |
| 34 | + * Non-retryable error. |
| 35 | + */ |
| 36 | +export class FileNotFoundError extends NonRetryableError { |
| 37 | + constructor(message: string) { |
| 38 | + super(message); |
| 39 | + this.name = 'FileNotFoundError'; |
| 40 | + } |
| 41 | +} |
| 42 | + |
| 43 | +/** |
| 44 | + * Error: File Modification Failed. |
| 45 | + * Indicates issues encountered while modifying a file, such as insufficient permissions or disk errors. |
| 46 | + * Non-retryable error. |
| 47 | + */ |
| 48 | +export class FileModificationError extends NonRetryableError { |
| 49 | + constructor(message: string) { |
| 50 | + super(message); |
| 51 | + this.name = 'FileModificationError'; |
| 52 | + } |
| 53 | +} |
| 54 | + |
| 55 | +/** |
| 56 | + * Error: Model Service Unavailable. |
| 57 | + * Indicates that the underlying model service cannot be reached or is down. |
| 58 | + * Retryable error, typically temporary. |
| 59 | + */ |
| 60 | +export class ModelUnavailableError extends RetryableError { |
| 61 | + constructor(message: string) { |
| 62 | + super(message); |
| 63 | + this.name = 'ModelUnavailableError'; |
| 64 | + } |
| 65 | +} |
| 66 | + |
| 67 | +/** |
| 68 | + * Error: Response Parsing Failed. |
| 69 | + * Indicates that the system could not properly parse the response data. |
| 70 | + * Retryable error, possibly due to temporary data format issues. |
| 71 | + */ |
| 72 | +export class ResponseParsingError extends RetryableError { |
| 73 | + constructor(message: string) { |
| 74 | + super(message); |
| 75 | + this.name = 'ResponseParsingError'; |
| 76 | + } |
| 77 | +} |
| 78 | + |
| 79 | +/** |
| 80 | + * Error: Response Tag Error. |
| 81 | + * Indicates that expected tags in the response are missing or invalid during content generation or parsing. |
| 82 | + * Non-retryable error. |
| 83 | + */ |
| 84 | +export class ResponseTagError extends NonRetryableError { |
| 85 | + constructor(message: string) { |
| 86 | + super(message); |
| 87 | + this.name = 'ResponseTagError'; |
| 88 | + } |
| 89 | +} |
| 90 | + |
| 91 | +/** |
| 92 | + * Error: Temporary Service Unavailable. |
| 93 | + * Indicates that the service is unavailable due to temporary issues like server overload or maintenance. |
| 94 | + * Retryable error, typically temporary. |
| 95 | + */ |
| 96 | +export class TemporaryServiceUnavailableError extends RetryableError { |
| 97 | + constructor(message: string) { |
| 98 | + super(message); |
| 99 | + this.name = 'TemporaryServiceUnavailableError'; |
| 100 | + } |
| 101 | +} |
| 102 | + |
| 103 | +/** |
| 104 | + * Error: Rate Limit Exceeded. |
| 105 | + * Indicates that too many requests have been sent within a given time frame. |
| 106 | + * Retryable error, may require waiting before retrying. |
| 107 | + */ |
| 108 | +export class RateLimitExceededError extends RetryableError { |
| 109 | + constructor(message: string) { |
| 110 | + super(message); |
| 111 | + this.name = 'RateLimitExceededError'; |
| 112 | + } |
| 113 | +} |
| 114 | + |
| 115 | +/** |
| 116 | + * Error: Missing Configuration. |
| 117 | + * Indicates issues with system setup or missing configuration parameters. |
| 118 | + * Non-retryable error, typically requires manual configuration fixes. |
| 119 | + */ |
| 120 | +export class MissingConfigurationError extends NonRetryableError { |
| 121 | + constructor(message: string) { |
| 122 | + super(message); |
| 123 | + this.name = 'MissingConfigurationError'; |
| 124 | + } |
| 125 | +} |
| 126 | + |
| 127 | +/** |
| 128 | + * Error: Invalid Parameter. |
| 129 | + * Indicates that a function argument or configuration parameter is invalid. |
| 130 | + * Non-retryable error, typically requires correcting the input parameters. |
| 131 | + */ |
| 132 | +export class InvalidParameterError extends NonRetryableError { |
| 133 | + constructor(message: string) { |
| 134 | + super(message); |
| 135 | + this.name = 'InvalidParameterError'; |
| 136 | + } |
| 137 | +} |
| 138 | + |
| 139 | +/** |
| 140 | + * Error: File Write Failed. |
| 141 | + * Indicates issues encountered while writing to a file, such as insufficient permissions or disk errors. |
| 142 | + * Non-retryable error. |
| 143 | + */ |
| 144 | +export class FileWriteError extends NonRetryableError { |
| 145 | + constructor(message: string) { |
| 146 | + super(message); |
| 147 | + this.name = 'FileWriteError'; |
| 148 | + } |
| 149 | +} |
0 commit comments