From 22e509c1efb2260e1537c78684f1a5e9f053b75a Mon Sep 17 00:00:00 2001 From: CaIon Date: Thu, 16 Apr 2026 20:56:44 +0800 Subject: [PATCH] refactor: simplify ShouldDisableChannel function by removing unused parameters and commented-out code --- controller/channel-test.go | 2 +- controller/relay.go | 2 +- service/channel.go | 37 +------------------------------------ 3 files changed, 3 insertions(+), 38 deletions(-) diff --git a/controller/channel-test.go b/controller/channel-test.go index db0326d3..8d62a4ac 100644 --- a/controller/channel-test.go +++ b/controller/channel-test.go @@ -830,7 +830,7 @@ func testAllChannels(notify bool) error { newAPIError := result.newAPIError // request error disables the channel if newAPIError != nil { - shouldBanChannel = service.ShouldDisableChannel(channel.Type, result.newAPIError) + shouldBanChannel = service.ShouldDisableChannel(result.newAPIError) } // 当错误检查通过,才检查响应时间 diff --git a/controller/relay.go b/controller/relay.go index a6f3f035..c97ab45b 100644 --- a/controller/relay.go +++ b/controller/relay.go @@ -351,7 +351,7 @@ func processChannelError(c *gin.Context, channelError types.ChannelError, err *t logger.LogError(c, fmt.Sprintf("channel error (channel #%d, status code: %d): %s", channelError.ChannelId, err.StatusCode, err.Error())) // 不要使用context获取渠道信息,异步处理时可能会出现渠道信息不一致的情况 // do not use context to get channel info, there may be inconsistent channel info when processing asynchronously - if service.ShouldDisableChannel(channelError.ChannelType, err) && channelError.AutoBan { + if service.ShouldDisableChannel(err) && channelError.AutoBan { gopool.Go(func() { service.DisableChannel(channelError, err.ErrorWithStatusCode()) }) diff --git a/service/channel.go b/service/channel.go index f93b29a2..3fde6e20 100644 --- a/service/channel.go +++ b/service/channel.go @@ -42,7 +42,7 @@ func EnableChannel(channelId int, usingKey string, channelName string) { } } -func ShouldDisableChannel(channelType int, err *types.NewAPIError) bool { +func ShouldDisableChannel(err *types.NewAPIError) bool { if !common.AutomaticDisableChannelEnabled { return false } @@ -58,41 +58,6 @@ func ShouldDisableChannel(channelType int, err *types.NewAPIError) bool { if operation_setting.ShouldDisableByStatusCode(err.StatusCode) { return true } - //if err.StatusCode == http.StatusUnauthorized { - // return true - //} - //if err.StatusCode == http.StatusForbidden { - // switch channelType { - // case constant.ChannelTypeGemini: - // return true - // } - //} - oaiErr := err.ToOpenAIError() - switch oaiErr.Code { - case "invalid_api_key": - return true - case "account_deactivated": - return true - case "billing_not_active": - return true - case "pre_consume_token_quota_failed": - return true - case "Arrearage": - return true - } - switch oaiErr.Type { - case "insufficient_quota": - return true - case "insufficient_user_quota": - return true - // https://docs.anthropic.com/claude/reference/errors - case "authentication_error": - return true - case "permission_error": - return true - case "forbidden": - return true - } lowerMessage := strings.ToLower(err.Error()) search, _ := AcSearch(lowerMessage, operation_setting.AutomaticDisableKeywords, true)