589
}
590
if (err instanceof CopilotApiError) {
592
>
// status before headers are sent. Coerce to 502 so we
593
>
// don't ship a 520 with a JSON body that violates HTTP
594
>
// semantics for the consumer.
595
>
const status = err.status === COPILOT_API_ERROR_STATUS_STREAMING ? 502 : err.status;
596
>
writeUpstreamJsonError(res, status, embedChatError ? embedForwardedChatError(err) : err.envelope);
597
>
return;
598
>
}
599
writeJsonError(res, 502, 'api_error', err instanceof Error ? err.message : String(err));
600
}