mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-02 20:40:52 +08:00
feat: add client availability tracking and error handling improvements
- Introduced `IsAvailable` and `SetUnavailable` methods to clients for availability tracking. - Integrated availability checks in client selection logic to skip unavailable clients. - Enhanced error handling by marking clients unavailable on specific error codes (e.g., 401, 402). - Removed redundant quota verification logs in client reordering logic.
This commit is contained in:
@@ -146,9 +146,13 @@ func (h *OpenAIResponsesAPIHandler) handleNonStreamingResponse(c *gin.Context, r
|
||||
errRefreshTokens := cliClient.RefreshTokens(cliCtx)
|
||||
if errRefreshTokens != nil {
|
||||
log.Debugf("refresh token failed, switch client, %s", util.HideAPIKey(cliClient.GetEmail()))
|
||||
cliClient.SetUnavailable()
|
||||
}
|
||||
retryCount++
|
||||
continue
|
||||
case 402:
|
||||
cliClient.SetUnavailable()
|
||||
continue
|
||||
default:
|
||||
// Forward other errors directly to the client
|
||||
c.Status(err.StatusCode)
|
||||
@@ -260,6 +264,18 @@ outLoop:
|
||||
log.Debugf("http status code %d, switch client", err.StatusCode)
|
||||
retryCount++
|
||||
continue outLoop
|
||||
case 401:
|
||||
log.Debugf("unauthorized request, try to refresh token, %s", util.HideAPIKey(cliClient.GetEmail()))
|
||||
errRefreshTokens := cliClient.RefreshTokens(cliCtx)
|
||||
if errRefreshTokens != nil {
|
||||
log.Debugf("refresh token failed, switch client, %s", util.HideAPIKey(cliClient.GetEmail()))
|
||||
cliClient.SetUnavailable()
|
||||
}
|
||||
retryCount++
|
||||
continue outLoop
|
||||
case 402:
|
||||
cliClient.SetUnavailable()
|
||||
continue outLoop
|
||||
default:
|
||||
// Forward other errors directly to the client
|
||||
c.Status(err.StatusCode)
|
||||
|
||||
Reference in New Issue
Block a user