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

This commit is contained in:
Frank 2025-12-18 00:47:36 -05:00
parent 57ef115375
commit 647331de28

View file

@ -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,
})