Commit 329416d6 by Seefs

fix(relay): skip retries for bad response body errors

parent 57d52586
......@@ -341,6 +341,9 @@ func shouldRetry(c *gin.Context, openaiErr *types.NewAPIError, retryTimes int) b
if code < 100 || code > 599 {
return true
}
if operation_setting.IsAlwaysSkipRetryCode(openaiErr.GetErrorCode()) {
return false
}
return operation_setting.ShouldRetryByStatusCode(code)
}
......
......@@ -5,6 +5,8 @@ import (
"sort"
"strconv"
"strings"
"github.com/QuantumNous/new-api/types"
)
type StatusCodeRange struct {
......@@ -31,6 +33,10 @@ var alwaysSkipRetryStatusCodes = map[int]struct{}{
524: {},
}
var alwaysSkipRetryCodes = map[types.ErrorCode]struct{}{
types.ErrorCodeBadResponseBody: {},
}
func AutomaticDisableStatusCodesToString() string {
return statusCodeRangesToString(AutomaticDisableStatusCodeRanges)
}
......@@ -66,6 +72,11 @@ func IsAlwaysSkipRetryStatusCode(code int) bool {
return exists
}
func IsAlwaysSkipRetryCode(errorCode types.ErrorCode) bool {
_, exists := alwaysSkipRetryCodes[errorCode]
return exists
}
func ShouldRetryByStatusCode(code int) bool {
if IsAlwaysSkipRetryStatusCode(code) {
return false
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment