MCPcopy Index your code
hub / github.com/aiprodcoder/MIXAPI / shouldRetry

Function shouldRetry

controller/relay.go:276–320  ·  view source on GitHub ↗
(c *gin.Context, openaiErr *types.NewAPIError, retryTimes int)

Source from the content-addressed store, hash-verified

274}
275
276func shouldRetry(c *gin.Context, openaiErr *types.NewAPIError, retryTimes int) bool {
277 if openaiErr == nil {
278 return false
279 }
280 if types.IsChannelError(openaiErr) {
281 return true
282 }
283 if types.IsLocalError(openaiErr) {
284 return false
285 }
286 if retryTimes <= 0 {
287 return false
288 }
289 if _, ok := c.Get("specific_channel_id"); ok {
290 return false
291 }
292 if openaiErr.StatusCode == http.StatusTooManyRequests {
293 return true
294 }
295 if openaiErr.StatusCode == 307 {
296 return true
297 }
298 if openaiErr.StatusCode/100 == 5 {
299 // 超时不重试
300 if openaiErr.StatusCode == 504 || openaiErr.StatusCode == 524 {
301 return false
302 }
303 return true
304 }
305 if openaiErr.StatusCode == http.StatusBadRequest {
306 channelType := c.GetInt("channel_type")
307 if channelType == constant.ChannelTypeAnthropic {
308 return true
309 }
310 return false
311 }
312 if openaiErr.StatusCode == 408 {
313 // azure处理超时不重试
314 return false
315 }
316 if openaiErr.StatusCode/100 == 2 {
317 return false
318 }
319 return true
320}
321
322func processChannelError(c *gin.Context, channelError types.ChannelError, err *types.NewAPIError) {
323 // 不要使用context获取渠道信息,异步处理时可能会出现渠道信息不一致的情况

Callers 3

RelayFunction · 0.85
WssRelayFunction · 0.85
RelayClaudeFunction · 0.85

Calls 3

IsChannelErrorFunction · 0.92
IsLocalErrorFunction · 0.92
GetMethod · 0.80

Tested by

no test coverage detected