From a1540e27c22091771276c6d677bb96dcfae58ce1 Mon Sep 17 00:00:00 2001 From: Wei Shaw Date: Wed, 31 Dec 2025 11:46:53 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E5=A4=8D=20OpenAI=20402=20?= =?UTF-8?q?=E6=8A=A5=E9=94=99=E8=87=AA=E5=8A=A8=E5=88=87=E6=8D=A2=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/openai_gateway_service.go | 6 +- backend/internal/service/ratelimit_service.go | 4 + frontend/src/components/common/Modal.vue | 120 ++++++++++++++++++ 3 files changed, 129 insertions(+), 1 deletion(-) create mode 100755 frontend/src/components/common/Modal.vue diff --git a/backend/internal/service/openai_gateway_service.go b/backend/internal/service/openai_gateway_service.go index 2bb0bee8..912c25af 100644 --- a/backend/internal/service/openai_gateway_service.go +++ b/backend/internal/service/openai_gateway_service.go @@ -240,7 +240,7 @@ func (s *OpenAIGatewayService) GetAccessToken(ctx context.Context, account *Acco func (s *OpenAIGatewayService) shouldFailoverUpstreamError(statusCode int) bool { switch statusCode { - case 401, 403, 429, 529: + case 401, 402, 403, 429, 529: return true default: return statusCode >= 500 @@ -454,6 +454,10 @@ func (s *OpenAIGatewayService) handleErrorResponse(ctx context.Context, resp *ht statusCode = http.StatusBadGateway errType = "upstream_error" errMsg = "Upstream authentication failed, please contact administrator" + case 402: + statusCode = http.StatusBadGateway + errType = "upstream_error" + errMsg = "Upstream payment required: insufficient balance or billing issue" case 403: statusCode = http.StatusBadGateway errType = "upstream_error" diff --git a/backend/internal/service/ratelimit_service.go b/backend/internal/service/ratelimit_service.go index 27b6d3c8..1474ae46 100644 --- a/backend/internal/service/ratelimit_service.go +++ b/backend/internal/service/ratelimit_service.go @@ -39,6 +39,10 @@ func (s *RateLimitService) HandleUpstreamError(ctx context.Context, account *Acc // 认证失败:停止调度,记录错误 s.handleAuthError(ctx, account, "Authentication failed (401): invalid or expired credentials") return true + case 402: + // 支付要求:余额不足或计费问题,停止调度 + s.handleAuthError(ctx, account, "Payment required (402): insufficient balance or billing issue") + return true case 403: // 禁止访问:停止调度,记录错误 s.handleAuthError(ctx, account, "Access forbidden (403): account may be suspended or lack permissions") diff --git a/frontend/src/components/common/Modal.vue b/frontend/src/components/common/Modal.vue new file mode 100755 index 00000000..89304de1 --- /dev/null +++ b/frontend/src/components/common/Modal.vue @@ -0,0 +1,120 @@ + + +