1237
1238
if (type === 'error') {
1240
>
// Anthropic shape (so any extra fields propagate to Phase 2's
1241
>
// passthrough proxy). Fall back to a clean api_error synthesis
1242
>
// when fields are missing or `error` is unstructured.
1243
>
const rawError = (parsed as { error?: unknown }).error;
1244
>
let envelope: Anthropic.ErrorResponse;
1245
>
if (
1246
>
rawError && typeof rawError === 'object'
1247
&& typeof (rawError as { type?: unknown }).type === 'string'
1248
&& typeof (rawError as { message?: unknown }).message === 'string'
1250
envelope = parsed as Anthropic.ErrorResponse;
1252
let errorMessage: string;
1253
if (typeof rawError === 'string') {