mirror of
https://github.com/sst/opencode.git
synced 2025-12-23 10:11:41 +00:00
zen: error handling for stream requests
Some checks are pending
deploy / deploy (push) Waiting to run
generate / generate (push) Waiting to run
publish / publish (push) Waiting to run
publish / publish-tauri (map[host:blacksmith-4vcpu-ubuntu-2404 target:x86_64-unknown-linux-gnu]) (push) Blocked by required conditions
publish / publish-tauri (map[host:blacksmith-4vcpu-windows-2025 target:x86_64-pc-windows-msvc]) (push) Blocked by required conditions
publish / publish-tauri (map[host:macos-latest target:aarch64-apple-darwin]) (push) Blocked by required conditions
publish / publish-tauri (map[host:macos-latest target:x86_64-apple-darwin]) (push) Blocked by required conditions
publish / publish-release (push) Blocked by required conditions
test / test (push) Waiting to run
Update Nix Hashes / update (push) Waiting to run
Some checks are pending
deploy / deploy (push) Waiting to run
generate / generate (push) Waiting to run
publish / publish (push) Waiting to run
publish / publish-tauri (map[host:blacksmith-4vcpu-ubuntu-2404 target:x86_64-unknown-linux-gnu]) (push) Blocked by required conditions
publish / publish-tauri (map[host:blacksmith-4vcpu-windows-2025 target:x86_64-pc-windows-msvc]) (push) Blocked by required conditions
publish / publish-tauri (map[host:macos-latest target:aarch64-apple-darwin]) (push) Blocked by required conditions
publish / publish-tauri (map[host:macos-latest target:x86_64-apple-darwin]) (push) Blocked by required conditions
publish / publish-release (push) Blocked by required conditions
test / test (push) Waiting to run
Update Nix Hashes / update (push) Waiting to run
This commit is contained in:
parent
57ef115375
commit
647331de28
1 changed files with 6 additions and 19 deletions
|
|
@ -143,6 +143,9 @@ export async function handler(
|
|||
// Store sticky provider
|
||||
await stickyTracker?.set(providerInfo.id)
|
||||
|
||||
// Temporarily change 404 to 400 status code b/c solid start automatically override 404 response
|
||||
const resStatus = res.status === 404 ? 400 : res.status
|
||||
|
||||
// Scrub response headers
|
||||
const resHeaders = new Headers()
|
||||
const keepHeaders = ["content-type", "cache-control"]
|
||||
|
|
@ -153,7 +156,7 @@ export async function handler(
|
|||
}
|
||||
logger.debug("STATUS: " + res.status + " " + res.statusText)
|
||||
|
||||
// Handle non-streaming response for non-stream request
|
||||
// Handle non-streaming response
|
||||
if (!isStream) {
|
||||
const responseConverter = createResponseConverter(providerInfo.format, opts.format)
|
||||
const json = await res.json()
|
||||
|
|
@ -168,23 +171,7 @@ export async function handler(
|
|||
await trackUsage(authInfo, modelInfo, providerInfo, tokensInfo)
|
||||
await reload(authInfo)
|
||||
return new Response(body, {
|
||||
status: res.status,
|
||||
statusText: res.statusText,
|
||||
headers: resHeaders,
|
||||
})
|
||||
}
|
||||
|
||||
// Handle non-streaming response for stream request
|
||||
const contentType = res.headers.get("content-type") ?? ""
|
||||
if (!contentType.includes("text/event-stream")) {
|
||||
const body = await res.text()
|
||||
logger.metric({ response_length: body.length })
|
||||
logger.debug("RESPONSE: " + body)
|
||||
dataDumper?.provideResponse(body)
|
||||
dataDumper?.flush()
|
||||
await rateLimiter?.track()
|
||||
return new Response(body, {
|
||||
status: res.status,
|
||||
status: resStatus,
|
||||
statusText: res.statusText,
|
||||
headers: resHeaders,
|
||||
})
|
||||
|
|
@ -262,7 +249,7 @@ export async function handler(
|
|||
})
|
||||
|
||||
return new Response(stream, {
|
||||
status: res.status,
|
||||
status: resStatus,
|
||||
statusText: res.statusText,
|
||||
headers: resHeaders,
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue