2026-02-16 14:52:03 +00:00
|
|
|
type BatchOutputErrorLike = {
|
|
|
|
|
error?: { message?: string };
|
|
|
|
|
response?: {
|
2026-02-22 21:35:11 +00:00
|
|
|
body?:
|
|
|
|
|
| string
|
|
|
|
|
| {
|
|
|
|
|
error?: { message?: string };
|
|
|
|
|
};
|
2026-02-16 14:52:03 +00:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2026-02-22 21:35:11 +00:00
|
|
|
function getResponseErrorMessage(line: BatchOutputErrorLike | undefined): string | undefined {
|
|
|
|
|
const body = line?.response?.body;
|
2026-02-22 19:03:56 -05:00
|
|
|
if (typeof body === "string") {
|
|
|
|
|
return body || undefined;
|
|
|
|
|
}
|
2026-02-22 21:35:11 +00:00
|
|
|
if (!body || typeof body !== "object") {
|
|
|
|
|
return undefined;
|
|
|
|
|
}
|
|
|
|
|
return typeof body.error?.message === "string" ? body.error.message : undefined;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-16 14:52:03 +00:00
|
|
|
export function extractBatchErrorMessage(lines: BatchOutputErrorLike[]): string | undefined {
|
2026-02-22 21:35:11 +00:00
|
|
|
const first = lines.find((line) => line.error?.message || getResponseErrorMessage(line));
|
|
|
|
|
return first?.error?.message ?? getResponseErrorMessage(first);
|
2026-02-16 14:52:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function formatUnavailableBatchError(err: unknown): string | undefined {
|
|
|
|
|
const message = err instanceof Error ? err.message : String(err);
|
|
|
|
|
return message ? `error file unavailable: ${message}` : undefined;
|
|
|
|
|
}
|