Better error messages on OpenRouter via openai-completions
This commit is contained in:
@@ -307,6 +307,9 @@ export const streamOpenAICompletions: StreamFunction<"openai-completions"> = (
|
|||||||
for (const block of output.content) delete (block as any).index;
|
for (const block of output.content) delete (block as any).index;
|
||||||
output.stopReason = options?.signal?.aborted ? "aborted" : "error";
|
output.stopReason = options?.signal?.aborted ? "aborted" : "error";
|
||||||
output.errorMessage = error instanceof Error ? error.message : JSON.stringify(error);
|
output.errorMessage = error instanceof Error ? error.message : JSON.stringify(error);
|
||||||
|
// Some providers via OpenRouter give additional information in this field.
|
||||||
|
const rawMetadata = (error as any)?.error?.metadata?.raw;
|
||||||
|
if (rawMetadata) output.errorMessage += `\n${rawMetadata}`;
|
||||||
stream.push({ type: "error", reason: output.stopReason, error: output });
|
stream.push({ type: "error", reason: output.stopReason, error: output });
|
||||||
stream.end();
|
stream.end();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user