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
26 changes: 25 additions & 1 deletion src/actions/providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1057,6 +1057,30 @@ function extractErrorMessage(errorJson: unknown): string | undefined {
return undefined;
}

const obj = errorJson as Record<string, unknown>;

// 优先提取 upstream_error 中的错误信息(针对中转服务的嵌套错误)
const upstreamError = (obj.error as { upstream_error?: unknown } | undefined)?.upstream_error;

if (upstreamError && typeof upstreamError === "object") {
const upstreamErrorObj = upstreamError as Record<string, unknown>;

// 尝试从 upstream_error.error.message 提取
const nestedMessage = normalizeErrorValue(
(upstreamErrorObj.error as { message?: unknown } | undefined)?.message
);
if (nestedMessage) {
return nestedMessage;
}

// 尝试从 upstream_error.message 提取
const directMessage = normalizeErrorValue(upstreamErrorObj.message);
if (directMessage) {
return directMessage;
}
}

// 常规错误提取逻辑(保持原有优先级)
const candidates: Array<(obj: Record<string, unknown>) => unknown> = [
(obj) => (obj.error as Record<string, unknown> | undefined)?.message,
(obj) => obj.message,
Expand All @@ -1069,7 +1093,7 @@ function extractErrorMessage(errorJson: unknown): string | undefined {
for (const getter of candidates) {
let value: unknown;
try {
value = getter(errorJson as Record<string, unknown>);
value = getter(obj);
} catch {
continue;
}
Expand Down
Loading