mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-11-28 12:53:30 +08:00
fix(openai,codex): build stream errors via ojson.Doc and preserve SSE status
- Build OpenAI Responses stream error and failed chunks directly through ojson.Doc with single-exit serialization, supporting scalar error strings without map mutations. - Preserve valid top-level and body envelope HTTP error status codes when normalizing typeless Codex SSE failures and Responses SSE frames. - Normalize scalar and blank WebSocket error fields purely via ojson.Doc.
This commit is contained in:
@@ -91,9 +91,16 @@ func buildCodexWebsocketErrorPayload(payload []byte, status int) []byte {
|
||||
}
|
||||
|
||||
fillBlankErrorMessage := func() {
|
||||
if node := doc.Get("error"); node.Type == ojson.String && strings.TrimSpace(node.String()) != "" {
|
||||
_ = doc.Set("error", map[string]any{"message": node.String()})
|
||||
return
|
||||
if node := doc.Get("error"); !node.IsObject() {
|
||||
scalar := ""
|
||||
if node.Type != ojson.Null && strings.TrimSpace(node.String()) != "" {
|
||||
scalar = node.String()
|
||||
}
|
||||
_ = doc.SetRawBytes("error", []byte(`{}`))
|
||||
if scalar != "" {
|
||||
_ = doc.Set("error.message", scalar)
|
||||
return
|
||||
}
|
||||
}
|
||||
if strings.TrimSpace(doc.Get("error.message").String()) != "" {
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user