Skip to content

fix: Chat/Messages 非流式错误响应透传上游错误详情#629

Open
fengshao1227 wants to merge 1 commit into
chenyme:mainfrom
fengshao1227:fix/conversation-error-passthrough
Open

fix: Chat/Messages 非流式错误响应透传上游错误详情#629
fengshao1227 wants to merge 1 commit into
chenyme:mainfrom
fengshao1227:fix/conversation-error-passthrough

Conversation

@fengshao1227

Copy link
Copy Markdown
Contributor

Summary

Closes #628

Chat/Messages 非流式分支(adapter.go:162)无条件将所有响应体通过 ConvertResponseJSONWithOptions 转换,包括非 2xx 错误响应。当上游返回非标准格式的错误(HTML、纯文本、非 Responses API JSON)时,转换失败导致原始错误信息丢失。

影响:所有通过 /v1/chat/completions/v1/messagesstream: false 调用的用户,在遇到 429(限流)、401(认证失败)、500(上游错误)等情况时,收不到有意义的错误信息。

Root Cause

Responses 路径(第 134 行)和流式路径(第 158 行)都有 resp.StatusCode >= 200 && resp.StatusCode < 300 守卫,但非流式 else 分支没有。

Fix

  • 非 2xx 响应仍先尝试转换(上游可能返回标准 Responses API error 格式)
  • 转换失败时,非 2xx 响应直接透传原始 body(保留上游错误详情)
  • 2xx 响应转换失败仍返回 Go error(行为不变)

Test plan

  • go build ./... 编译通过
  • go test ./... 全量通过(57 包,0 失败)
  • 自审覆盖所有 4 种组合(流式/非流式 × 2xx/非2xx)

…responses

The conversation (Chat/Messages) non-streaming branch unconditionally
fed all response bodies through ConvertResponseJSONWithOptions,
including non-2xx error responses. When the upstream returned a
non-standard error format (HTML, plain text, or non-Responses-API
JSON), the conversion failed and the original error details — rate
limit info, auth failure messages, quota errors — were swallowed.

Now: attempt conversion first (upstream may return a standard
Responses API error), and if conversion fails on a non-2xx response,
fall back to passing through the original body unchanged. This
matches the Responses path (line 134) which already guards on 2xx.

Closes chenyme#628
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Chat/Messages 非流式错误响应被 ConvertResponseJSON 转换,上游错误详情丢失

1 participant