mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-03 04:50:52 +08:00
Add token refresh handling for 401 responses across clients
- Implemented `RefreshTokens` method in client interfaces and Gemini clients. - Updated handlers to call `RefreshTokens` on 401 responses and retry requests if token refresh succeeds. - Enhanced error handling and retry logic to accommodate token refresh flow.
This commit is contained in:
@@ -275,6 +275,14 @@ func (h *GeminiCLIAPIHandler) handleInternalGenerateContent(c *gin.Context, rawJ
|
||||
log.Debugf("http status code %d, switch client", err.StatusCode)
|
||||
retryCount++
|
||||
continue
|
||||
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()))
|
||||
}
|
||||
retryCount++
|
||||
continue
|
||||
default:
|
||||
// Forward other errors directly to the client
|
||||
c.Status(err.StatusCode)
|
||||
|
||||
Reference in New Issue
Block a user