94
*/
95
export function buildForwardedChatError(err: CopilotApiError): IForwardedChatError {
96
>
const status = err.status === COPILOT_API_ERROR_STATUS_STREAMING ? 502 : err.status;
forwardedChatError.ts
97
>
const requestId = typeof err.envelope.request_id === 'string' ? err.envelope.request_id : '';
98
>
// CAPI rate-limit/quota errors carry their fine-grained code in the
99
>
// response body (e.g. `{ "error": { "code": "quota_exceeded", ... } }`).
100
>
// The proxy synthesizes a non-conforming body into the Anthropic envelope
101
>
// as `error.type: 'api_error'` with the raw body as the message, so prefer
102
>
// a CAPI code/message parsed out of the message when present.
103
>
const capiError = extractCapiError(err.envelope.error.message) ?? { code: err.envelope.error.type, message: err.envelope.error.message };
104
>
return {
105
>
fetchError: {
106
>
type: statusToFetchType(status),
107
>
reason: capiError.message ?? err.envelope.error.message,
108
>
requestId,
109
>
capiError,
110
>
},
111
>
};
112
>
}
113
114
/**