9 lines
846 B
TypeScript
9 lines
846 B
TypeScript
// UI presentation only: the web proxy preserves the native HTTP response unchanged.
|
|
// Gateways and unavailable-backend responses need not use LTX's error schema.
|
|
export function normalizeResponseError(payload: unknown): { code: string; message: string; [key: string]: unknown } {
|
|
const record = payload && typeof payload === 'object' ? payload as Record<string, unknown> : {}
|
|
const nested = record.error && typeof record.error === 'object' ? record.error as Record<string, unknown> : {}
|
|
const message = [record.message, nested.message, record.error, record.detail, payload].find(value => typeof value === 'string' && value.length > 0)
|
|
return { ...record, code: typeof record.code === 'string' ? record.code : 'HTTP_ERROR', message: typeof message === 'string' ? message : 'The backend rejected this request. See technical details.' }
|
|
}
|