Static analyzeAnalyzes an error from an AI provider and returns standardized error information. This method extracts relevant details from provider-specific error formats and maps them to a consistent structure for easier handling.
The error object thrown by the provider SDK
Optional providerName: stringOptional name of the provider for context
Standardized error information
const errorInfo = ErrorAnalyzer.analyzeError(error, 'Anthropic');
console.log(`Error type: ${errorInfo.errorType}`);
console.log(`Can retry: ${errorInfo.severity !== 'Fatal'}`);
Private Static canPrivate Determines whether an error can potentially be resolved by switching providers.
Strategy: We're permissive with failover - most errors should allow trying another provider/model since vendors may use different status codes and error messages. Only block failover for clear client-side structural errors that won't be fixed by switching.
The categorized error type
True if failover might help, false otherwise
Private Static determinePrivate Determines the standardized error type based on status code and error properties. Uses a combination of HTTP status codes, error messages, and error class names.
The error object to analyze
Optional statusCode: numberThe HTTP status code if available
The categorized error type
Private Static determinePrivate Determines the error severity based on the error type. This helps decide whether to retry immediately, wait, or fail permanently.
The categorized error type
The severity level of the error
Private Static extractPrivate Extracts HTTP status code from various error object structures. Different provider SDKs store status codes in different locations.
The error object to extract status code from
The HTTP status code if found, undefined otherwise
Private Static extractPrivate Extracts the provider-specific error code from the error object. Different providers store error codes in different locations.
The error object to extract provider code from
The provider error code if found, undefined otherwise
Private Static extract
Utility class for analyzing errors from various AI providers and mapping them to standardized error information. This class provides a consistent way to interpret errors across different provider SDKs.
ErrorAnalyzer
Since
2.47.0
Example