fix: 使用 ?? 替代 || 运算符确保默认值正确设置

将逻辑或(||)运算符替换为空值合并(??)运算符,确保当配置值为0时不会被错误地替换为默认值。同时更新了相关日志信息以显示当前设置的maxErrorCount值。
This commit is contained in:
hex2077 2025-12-04 18:05:38 +08:00
parent 211d677d00
commit 029d97236b
2 changed files with 5 additions and 4 deletions

View file

@ -21,8 +21,9 @@ export class ProviderPoolManager {
this.globalConfig = options.globalConfig || {}; // 存储全局配置
this.providerStatus = {}; // Tracks health and usage for each provider instance
this.roundRobinIndex = {}; // Tracks the current index for round-robin selection for each provider type
this.maxErrorCount = options.maxErrorCount || 3; // Default to 3 errors before marking unhealthy
this.healthCheckInterval = options.healthCheckInterval || 10 * 60 * 1000; // Default to 10 minutes
// 使用 ?? 运算符确保 0 也能被正确设置,而不是被 || 替换为默认值
this.maxErrorCount = options.maxErrorCount ?? 3; // Default to 3 errors before marking unhealthy
this.healthCheckInterval = options.healthCheckInterval ?? 10 * 60 * 1000; // Default to 10 minutes
// 日志级别控制
this.logLevel = options.logLevel || 'info'; // 'debug', 'info', 'warn', 'error'
@ -87,7 +88,7 @@ export class ProviderPoolManager {
});
});
}
this._log('info', 'Initialized provider statuses: ok');
this._log('info', `Initialized provider statuses: ok (maxErrorCount: ${this.maxErrorCount})`);
}
/**

View file

@ -14,7 +14,7 @@ export async function initApiService(config) {
if (config.providerPools && Object.keys(config.providerPools).length > 0) {
providerPoolManager = new ProviderPoolManager(config.providerPools, {
globalConfig: config,
maxErrorCount: config.MAX_ERROR_COUNT || 3
maxErrorCount: config.MAX_ERROR_COUNT ?? 3
});
console.log('[Initialization] ProviderPoolManager initialized with configured pools.');
// 健康检查将在服务器完全启动后执行