From d9e39f5906d2da71102e85bc4ead78f0a182deb5 Mon Sep 17 00:00:00 2001 From: JustSong Date: Sun, 21 May 2023 20:58:00 +0800 Subject: [PATCH] fix: disable channel with a whitelist --- controller/channel.go | 2 +- controller/relay.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/controller/channel.go b/controller/channel.go index 3f047546..965229fd 100644 --- a/controller/channel.go +++ b/controller/channel.go @@ -201,7 +201,7 @@ func testChannel(channel *model.Channel, request *ChatRequest) error { if err != nil { return err } - if response.Error.Message != "" { + if response.Error.Message != "" || response.Error.Code != "" { return errors.New(fmt.Sprintf("type %s, code %s, message %s", response.Error.Type, response.Error.Code, response.Error.Message)) } return nil diff --git a/controller/relay.go b/controller/relay.go index 83578141..81497d81 100644 --- a/controller/relay.go +++ b/controller/relay.go @@ -89,8 +89,8 @@ func Relay(c *gin.Context) { }) channelId := c.GetInt("channel_id") common.SysError(fmt.Sprintf("Relay error (channel #%d): %s", channelId, err.Message)) - if err.Type != "invalid_request_error" && err.StatusCode != http.StatusTooManyRequests && - common.AutomaticDisableChannelEnabled { + // https://platform.openai.com/docs/guides/error-codes/api-errors + if common.AutomaticDisableChannelEnabled && (err.Type == "insufficient_quota" || err.Code == "invalid_api_key") { channelId := c.GetInt("channel_id") channelName := c.GetString("channel_name") disableChannel(channelId, channelName, err.Message)