update
This commit is contained in:
@ -182,25 +182,41 @@ export class PlatformError extends Error {
|
||||
): PlatformError {
|
||||
const nextRetryAt = Date.now() + retryDelay;
|
||||
|
||||
// Create a new instance with the same parameters but updated context
|
||||
// Clone the error with updated context
|
||||
const newContext = {
|
||||
...this.context,
|
||||
retry: {
|
||||
maxRetries,
|
||||
currentRetry,
|
||||
nextRetryAt,
|
||||
retryDelay
|
||||
}
|
||||
};
|
||||
|
||||
// Create a new instance using the protected method that subclasses can override
|
||||
const newError = this.createWithContext(newContext);
|
||||
|
||||
// Update recoverability if we can retry
|
||||
if (currentRetry < maxRetries && newError.recoverability === ErrorRecoverability.NON_RECOVERABLE) {
|
||||
(newError as any).recoverability = ErrorRecoverability.MAYBE_RECOVERABLE;
|
||||
}
|
||||
|
||||
return newError;
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected method to create a new instance with updated context
|
||||
* Subclasses can override this to handle their own constructor signatures
|
||||
*/
|
||||
protected createWithContext(context: IErrorContext): PlatformError {
|
||||
// Default implementation for PlatformError
|
||||
return new (this.constructor as typeof PlatformError)(
|
||||
this.message,
|
||||
this.code,
|
||||
this.severity,
|
||||
this.category,
|
||||
// If we can retry, the error is at least maybe recoverable
|
||||
currentRetry < maxRetries
|
||||
? ErrorRecoverability.MAYBE_RECOVERABLE
|
||||
: this.recoverability,
|
||||
{
|
||||
...this.context,
|
||||
retry: {
|
||||
maxRetries,
|
||||
currentRetry,
|
||||
nextRetryAt,
|
||||
retryDelay
|
||||
}
|
||||
}
|
||||
this.recoverability,
|
||||
context
|
||||
);
|
||||
}
|
||||
|
||||
@ -247,6 +263,18 @@ export class ValidationError extends PlatformError {
|
||||
context
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance with updated context
|
||||
* Overrides the base implementation to handle ValidationError's constructor signature
|
||||
*/
|
||||
protected createWithContext(context: IErrorContext): PlatformError {
|
||||
return new (this.constructor as typeof ValidationError)(
|
||||
this.message,
|
||||
this.code,
|
||||
context
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -274,6 +302,18 @@ export class ConfigurationError extends PlatformError {
|
||||
context
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance with updated context
|
||||
* Overrides the base implementation to handle ConfigurationError's constructor signature
|
||||
*/
|
||||
protected createWithContext(context: IErrorContext): PlatformError {
|
||||
return new (this.constructor as typeof ConfigurationError)(
|
||||
this.message,
|
||||
this.code,
|
||||
context
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -301,6 +341,18 @@ export class NetworkError extends PlatformError {
|
||||
context
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance with updated context
|
||||
* Overrides the base implementation to handle NetworkError's constructor signature
|
||||
*/
|
||||
protected createWithContext(context: IErrorContext): PlatformError {
|
||||
return new (this.constructor as typeof NetworkError)(
|
||||
this.message,
|
||||
this.code,
|
||||
context
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -328,6 +380,18 @@ export class ResourceError extends PlatformError {
|
||||
context
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance with updated context
|
||||
* Overrides the base implementation to handle ResourceError's constructor signature
|
||||
*/
|
||||
protected createWithContext(context: IErrorContext): PlatformError {
|
||||
return new (this.constructor as typeof ResourceError)(
|
||||
this.message,
|
||||
this.code,
|
||||
context
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -355,6 +419,18 @@ export class AuthenticationError extends PlatformError {
|
||||
context
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance with updated context
|
||||
* Overrides the base implementation to handle AuthenticationError's constructor signature
|
||||
*/
|
||||
protected createWithContext(context: IErrorContext): PlatformError {
|
||||
return new (this.constructor as typeof AuthenticationError)(
|
||||
this.message,
|
||||
this.code,
|
||||
context
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -382,6 +458,18 @@ export class OperationError extends PlatformError {
|
||||
context
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance with updated context
|
||||
* Overrides the base implementation to handle OperationError's constructor signature
|
||||
*/
|
||||
protected createWithContext(context: IErrorContext): PlatformError {
|
||||
return new (this.constructor as typeof OperationError)(
|
||||
this.message,
|
||||
this.code,
|
||||
context
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user