Repository navigation
Show available causes of terminated API streams #2736
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -84,13 +84,20 @@ export function handleProviderError( | |
| if (error instanceof Error) { | ||
| const anyErr = error as any | ||
| const msg = anyErr?.error?.metadata?.raw || error.message || "" | ||
| const cause = error.cause | ||
| const causeCode = cause && typeof cause === "object" && "code" in cause ? cause.code : undefined | ||
| const causeDetail = | ||
| msg === "terminated" && cause instanceof Error | ||
| ? ` (response stream ended unexpectedly; cause: ${cause.message}${typeof causeCode === "string" ? `; code: ${causeCode}` : ""})` | ||
|
Comment on lines
+90
to
+91
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pass cause details through the message transformer. NanoGPT supplies a
|
||
| : "" | ||
|
|
||
| // Log the original error details for debugging | ||
| console.error(`[${providerName}] API error:`, { | ||
| message: msg, | ||
| name: error.name, | ||
| stack: error.stack, | ||
| status: anyErr.status, | ||
| cause, | ||
| statusCode: anyErr.statusCode, | ||
| }) | ||
|
|
||
|
|
@@ -104,8 +111,8 @@ export function handleProviderError( | |
| // Apply custom transformer if provided, otherwise use default format | ||
| const finalMessage = options?.messageTransformer | ||
| ? options.messageTransformer(msg) | ||
| : `${providerName} ${messagePrefix} error: ${msg}` | ||
| wrapped = new Error(finalMessage) | ||
| : `${providerName} ${messagePrefix} error: ${msg}${causeDetail}` | ||
| wrapped = new Error(finalMessage, { cause: error }) | ||
| } | ||
|
|
||
| // Preserve HTTP status and structured details for retry/backoff + UI | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Include details from object-shaped socket causes.
A cause such as
{ message: "socket closed", code: "ECONNRESET" }fails theErrorcheck. The displayed message omits both available details. Read validated string fields from object-shaped causes and add a regression test.