fix(openai): treat 401 {"detail":"Unauthorized"} as permanent auth failure

- ratelimit_service: detect non-standard OpenAI 401 format and permanently disable account
- account_test_service: mark account error on 401 during connection test

Made-with: Cursor
This commit is contained in:
QTom
2026-04-02 20:44:05 +08:00
parent f2e596f6ec
commit 1f6a73f0db
2 changed files with 15 additions and 0 deletions

View File

@@ -551,6 +551,11 @@ func (s *AccountTestService) testOpenAIAccountConnection(c *gin.Context, account
account.RateLimitResetAt = resetAt
}
}
// 401 Unauthorized: 标记账号为永久错误
if resp.StatusCode == http.StatusUnauthorized && s.accountRepo != nil {
errMsg := fmt.Sprintf("Authentication failed (401): %s", string(body))
_ = s.accountRepo.SetError(ctx, account.ID, errMsg)
}
return s.sendErrorAndEnd(c, fmt.Sprintf("API returned %d: %s", resp.StatusCode, string(body)))
}