Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/api/providers/openrouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -512,10 +512,13 @@ export class OpenRouterHandler extends BaseProvider implements SingleCompletionH
function makeOpenRouterErrorReadable(error: any) {
const metadata = error?.error?.metadata as { raw?: string; provider_name?: string } | undefined
const parsedJson = safeJsonParse(metadata?.raw)
const rawError = parsedJson as { error?: string & { message?: string }; detail?: string } | undefined
const rawError = parsedJson as
| { error?: string & { message?: string }; detail?: string; message?: string }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
| { error?: string & { message?: string }; detail?: string; message?: string }
| { error?: string | { message?: string }; detail?: string; message?: string }

Presumably this is more correct but less convenient down below?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep

| undefined

if (error?.code !== 429 && error?.code !== 418) {
const errorMessage = rawError?.error?.message ?? rawError?.error ?? rawError?.detail ?? error?.message
const errorMessage =
rawError?.error?.message ?? rawError?.error ?? rawError?.detail ?? rawError?.message ?? error?.message
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the horror!

hzw ;-)

throw new Error(`${metadata?.provider_name ?? "Provider"} error: ${errorMessage ?? "unknown error"}`)
}

Expand Down
Loading