Merge pull request #5832 from stephanmck/fix/provider-error-body-passthrough-5763

fix(ai): surface provider HTTP error body instead of opaque SDK message
This commit is contained in:
Mario Zechner
2026-06-29 16:58:24 +02:00
committed by GitHub
12 changed files with 580 additions and 36 deletions
+12 -4
View File
@@ -47,6 +47,7 @@ import type {
ToolCall,
ToolResultMessage,
} from "../types.ts";
import { normalizeProviderError } from "../utils/error-body.ts";
import { AssistantMessageEventStream } from "../utils/event-stream.ts";
import { providerHeadersToRecord } from "../utils/headers.ts";
import { parseStreamingJson } from "../utils/json-parse.ts";
@@ -327,15 +328,22 @@ const BEDROCK_DATA_RETENTION_DOCS_URL = "https://docs.aws.amazon.com/bedrock/lat
* detection) can distinguish error categories via simple string matching.
*/
function formatBedrockError(error: unknown): string {
const message = error instanceof Error ? error.message : JSON.stringify(error);
const dataRetentionHint = /data retention mode/i.test(message)
const norm = normalizeProviderError(error);
// Surface the raw HTTP body (with status) when the SDK did not fold it into
// the message; otherwise fall back to the message. This is what stops a
// gateway 403 from collapsing to `Unknown: UnknownError`.
const core =
!norm.messageCarriesBody && norm.status !== undefined && norm.body !== undefined
? `${norm.status}: ${norm.body}`
: norm.message;
const dataRetentionHint = /data retention mode/i.test(core)
? ` See ${BEDROCK_DATA_RETENTION_DOCS_URL} for supported data retention modes.`
: "";
if (error instanceof BedrockRuntimeServiceException) {
const prefix = BEDROCK_ERROR_PREFIXES[error.name] ?? error.name;
return `${prefix}: ${message}${dataRetentionHint}`;
return `${prefix}: ${core}${dataRetentionHint}`;
}
return `${message}${dataRetentionHint}`;
return `${core}${dataRetentionHint}`;
}
/**