Skip to content

Commit 6dc238d

Browse files
committed
Improve error handling for Mistral, Moonshot
1 parent c79df25 commit 6dc238d

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/api/providers/openrouter.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,10 +512,13 @@ export class OpenRouterHandler extends BaseProvider implements SingleCompletionH
512512
function makeOpenRouterErrorReadable(error: any) {
513513
const metadata = error?.error?.metadata as { raw?: string; provider_name?: string } | undefined
514514
const parsedJson = safeJsonParse(metadata?.raw)
515-
const rawError = parsedJson as { error?: string & { message?: string }; detail?: string } | undefined
515+
const rawError = parsedJson as
516+
| { error?: string & { message?: string }; detail?: string; message?: string }
517+
| undefined
516518

517519
if (error?.code !== 429 && error?.code !== 418) {
518-
const errorMessage = rawError?.error?.message ?? rawError?.error ?? rawError?.detail ?? error?.message
520+
const errorMessage =
521+
rawError?.error?.message ?? rawError?.error ?? rawError?.detail ?? rawError?.message ?? error?.message
519522
throw new Error(`${metadata?.provider_name ?? "Provider"} error: ${errorMessage ?? "unknown error"}`)
520523
}
521524

0 commit comments

Comments
 (0)