logging
This commit is contained in:
@@ -143,11 +143,43 @@ export class BaseApiClient {
|
||||
retryCount,
|
||||
// Add helpful context for developers
|
||||
troubleshooting: this.getTroubleshootingContext(error, path),
|
||||
isRetryable: this.isRetryableError(errorType),
|
||||
isConnectivity: errorType === 'NETWORK_ERROR' || errorType === 'TIMEOUT_ERROR',
|
||||
developerHint: this.getDeveloperHint(error, path, method),
|
||||
},
|
||||
error
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if error type is retryable
|
||||
*/
|
||||
private isRetryableError(errorType: ApiErrorType): boolean {
|
||||
const retryableTypes: ApiErrorType[] = [
|
||||
'NETWORK_ERROR',
|
||||
'SERVER_ERROR',
|
||||
'RATE_LIMIT_ERROR',
|
||||
'TIMEOUT_ERROR',
|
||||
];
|
||||
return retryableTypes.includes(errorType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get developer-friendly hint for troubleshooting
|
||||
*/
|
||||
private getDeveloperHint(error: Error, path: string, method: string): string {
|
||||
if (error.message.includes('fetch failed') || error.message.includes('Failed to fetch')) {
|
||||
return 'Check if API server is running and CORS is configured correctly';
|
||||
}
|
||||
if (error.message.includes('timeout')) {
|
||||
return 'Request timed out - consider increasing timeout or checking network';
|
||||
}
|
||||
if (error.message.includes('ECONNREFUSED')) {
|
||||
return 'Connection refused - verify API server address and port';
|
||||
}
|
||||
return 'Review network connection and API endpoint configuration';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get troubleshooting context for network errors
|
||||
*/
|
||||
@@ -359,17 +391,25 @@ export class BaseApiClient {
|
||||
const severity = error.getSeverity();
|
||||
const message = error.getDeveloperMessage();
|
||||
|
||||
// Log based on severity
|
||||
// Enhanced context for better debugging
|
||||
const enhancedContext = {
|
||||
...error.context,
|
||||
severity,
|
||||
isRetryable: error.isRetryable(),
|
||||
isConnectivity: error.isConnectivityIssue(),
|
||||
};
|
||||
|
||||
// Use appropriate log level
|
||||
if (severity === 'error') {
|
||||
this.logger.error(message, error, error.context);
|
||||
this.logger.error(message, error, enhancedContext);
|
||||
} else if (severity === 'warn') {
|
||||
this.logger.warn(message, error.context);
|
||||
this.logger.warn(message, enhancedContext);
|
||||
} else {
|
||||
this.logger.info(message, error.context);
|
||||
this.logger.info(message, enhancedContext);
|
||||
}
|
||||
|
||||
// Report to error tracking
|
||||
this.errorReporter.report(error, error.context);
|
||||
this.errorReporter.report(error, enhancedContext);
|
||||
}
|
||||
|
||||
protected get<T>(path: string, options?: BaseApiClientOptions): Promise<T> {
|
||||
|
||||
Reference in New Issue
Block a user