fix: JSON-encode error body in non-streaming 500 handlers - #171
Merged
solderzzc merged 1 commit intoSep 24, 2026
Merged
Conversation
The /v1/chat/completions and /v1/completions catch blocks built the error body by string interpolation with only " replaced by ', so a backslash or newline in the error text produced invalid JSON. Extract the JSONSerialization body from sseErrorChunk into errorJSON(_:) and use it in both handlers. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
solderzzc
force-pushed
the
fix/nonstreaming-error-json
branch
from
September 24, 2026 02:03
1468068 to
765b990
Compare
Member
|
Rebased this onto Locally on Xcode 26.3: builds clean, 179/179 tests pass, including |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #170, as discussed there.
Depends on #170 — this branch is stacked on it (reuses its JSON encoding). Until #170 merges, the diff here also shows #170's commits; the change for this PR is only the last commit, 1468068.
Problem
The non-streaming catch blocks for
/v1/chat/completionsand/v1/completionsbuilt the 500 body by string interpolation, replacing only"with'. A backslash or newline in the error text made the body invalid JSON.Change
JSONSerializationbody out ofsseErrorChunkinto a newerrorJSON(_:).sseErrorChunknow wraps it in the SSEdata:framing.errorJSON(error). The status code, headers and fields (message/type/code) are the same as before.ServerSSETests.testErrorJSONEncodesMessageAsValidJSON, which checks a message containing a quote, a backslash and a newline.Testing
swift test: 0 failures, including the new test and the existingtestErrorChunkEncodesMessageAsValidJSON.🤖 Generated with Claude Code