diff --git a/src/platform/packages/shared/kbn-unified-chart-section-viewer/src/components/observability/metrics/utils/esql_response_error.test.ts b/src/platform/packages/shared/kbn-unified-chart-section-viewer/src/components/observability/metrics/utils/esql_response_error.test.ts index 238d5b1358cc2..d0a5f15b8ce63 100644 --- a/src/platform/packages/shared/kbn-unified-chart-section-viewer/src/components/observability/metrics/utils/esql_response_error.test.ts +++ b/src/platform/packages/shared/kbn-unified-chart-section-viewer/src/components/observability/metrics/utils/esql_response_error.test.ts @@ -11,7 +11,6 @@ import { type EsqlResponseErrorCause, EsqlResponseError, extractEsqlEmbeddedError, - extractEsqlResponseErrorCause, formatErrorCause, } from './esql_response_error'; @@ -38,32 +37,33 @@ describe('formatErrorCause', () => { }); }); -describe('extractEsqlResponseErrorCause', () => { - it('extracts error cause from response error object', () => { +describe('extractEsqlEmbeddedError', () => { + it('returns cause when response has error object (no top-level status)', () => { expect( - extractEsqlResponseErrorCause({ + extractEsqlEmbeddedError({ error: { type: 'remote_transport_exception', reason: 'ccs query failed' }, }) ).toEqual({ - type: 'remote_transport_exception', - reason: 'ccs query failed', + cause: { + type: 'remote_transport_exception', + reason: 'ccs query failed', + }, + status: undefined, }); }); it('returns undefined when response has no error object', () => { - expect(extractEsqlResponseErrorCause({ columns: [], values: [] })).toBeUndefined(); + expect(extractEsqlEmbeddedError({ columns: [], values: [] })).toBeUndefined(); }); it('returns undefined when error is null', () => { - expect(extractEsqlResponseErrorCause({ error: null })).toBeUndefined(); + expect(extractEsqlEmbeddedError({ error: null })).toBeUndefined(); }); it('returns undefined when error is not an object', () => { - expect(extractEsqlResponseErrorCause({ error: 'not-an-object' })).toBeUndefined(); + expect(extractEsqlEmbeddedError({ error: 'not-an-object' })).toBeUndefined(); }); -}); -describe('extractEsqlEmbeddedError', () => { it('returns cause and top-level status when present', () => { expect( extractEsqlEmbeddedError({ @@ -76,26 +76,26 @@ describe('extractEsqlEmbeddedError', () => { }); }); - it('omits status when absent or not a finite number', () => { + it('leaves status undefined when absent or not a finite number', () => { expect( extractEsqlEmbeddedError({ error: { type: 'x', reason: 'y' }, }) - ).toEqual({ cause: { type: 'x', reason: 'y' } }); + ).toEqual({ cause: { type: 'x', reason: 'y' }, status: undefined }); expect( extractEsqlEmbeddedError({ error: { type: 'x', reason: 'y' }, status: '400', } as object) - ).toEqual({ cause: { type: 'x', reason: 'y' } }); + ).toEqual({ cause: { type: 'x', reason: 'y' }, status: undefined }); expect( extractEsqlEmbeddedError({ error: { type: 'x', reason: 'y' }, status: Number.NaN, }) - ).toEqual({ cause: { type: 'x', reason: 'y' } }); + ).toEqual({ cause: { type: 'x', reason: 'y' }, status: undefined }); }); }); diff --git a/src/platform/packages/shared/kbn-unified-chart-section-viewer/src/components/observability/metrics/utils/esql_response_error.ts b/src/platform/packages/shared/kbn-unified-chart-section-viewer/src/components/observability/metrics/utils/esql_response_error.ts index c5c4e1340273f..2f2d057c26591 100644 --- a/src/platform/packages/shared/kbn-unified-chart-section-viewer/src/components/observability/metrics/utils/esql_response_error.ts +++ b/src/platform/packages/shared/kbn-unified-chart-section-viewer/src/components/observability/metrics/utils/esql_response_error.ts @@ -45,16 +45,9 @@ export const extractEsqlEmbeddedError = (response: object): EsqlEmbeddedError | const status = typeof body.status === 'number' && Number.isFinite(body.status) ? body.status : undefined; - return { - cause: response.error as EsqlResponseErrorCause, - ...(status !== undefined ? { status } : {}), - }; + return { cause: response.error as EsqlResponseErrorCause, status }; }; -export const extractEsqlResponseErrorCause = ( - response: object -): EsqlResponseErrorCause | undefined => extractEsqlEmbeddedError(response)?.cause; - export class EsqlResponseError extends Error { public readonly type?: string; public readonly reason?: string;