fix: disable channel when 401 received (close #467)

This commit is contained in:
JustSong
2023-08-26 12:05:18 +08:00
parent efeb9a16ce
commit ac7c0f3a76
3 changed files with 7 additions and 3 deletions

View File

@@ -4,6 +4,7 @@ import (
"fmt"
"github.com/gin-gonic/gin"
"github.com/pkoukk/tiktoken-go"
"net/http"
"one-api/common"
)
@@ -95,13 +96,16 @@ func errorWrapper(err error, code string, statusCode int) *OpenAIErrorWithStatus
}
}
func shouldDisableChannel(err *OpenAIError) bool {
func shouldDisableChannel(err *OpenAIError, statusCode int) bool {
if !common.AutomaticDisableChannelEnabled {
return false
}
if err == nil {
return false
}
if statusCode == http.StatusUnauthorized {
return true
}
if err.Type == "insufficient_quota" || err.Code == "invalid_api_key" || err.Code == "account_deactivated" {
return true
}