From 649fe5683e6d5f9dcdce59cc3bf0242191f09c11 Mon Sep 17 00:00:00 2001 From: Ryland Herrick Date: Wed, 28 Oct 2020 18:12:29 -0500 Subject: [PATCH] Display top-level error reason if no shard info is available For EQL queries, error responses do not contain `failed_shards` information, and so our error toasts contained only a stack trace. With this addition, we'll fall back to the top-level `error.reason` if those fields are not present, giving the user better indication of what's going on without having to inspect the actual network response. --- src/plugins/data/public/search/errors/es_error.tsx | 8 +++++--- src/plugins/data/public/search/errors/utils.ts | 4 ++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/plugins/data/public/search/errors/es_error.tsx b/src/plugins/data/public/search/errors/es_error.tsx index 53d00159b836b..35f369d1f4309 100644 --- a/src/plugins/data/public/search/errors/es_error.tsx +++ b/src/plugins/data/public/search/errors/es_error.tsx @@ -22,7 +22,7 @@ import { EuiCodeBlock, EuiSpacer } from '@elastic/eui'; import { ApplicationStart } from 'kibana/public'; import { KbnError } from '../../../../kibana_utils/common'; import { IEsError } from './types'; -import { getRootCause } from './utils'; +import { getRootCause, getTopLevelCause } from './utils'; export class EsError extends KbnError { constructor(protected readonly err: IEsError) { @@ -31,13 +31,15 @@ export class EsError extends KbnError { public getErrorMessage(application: ApplicationStart) { const rootCause = getRootCause(this.err)?.reason; + const topLevelCause = getTopLevelCause(this.err)?.reason; + const cause = rootCause ?? topLevelCause; return ( <> - {rootCause ? ( + {cause ? ( - {rootCause} + {cause} ) : null} diff --git a/src/plugins/data/public/search/errors/utils.ts b/src/plugins/data/public/search/errors/utils.ts index d07d9b05e91e9..45a318904665f 100644 --- a/src/plugins/data/public/search/errors/utils.ts +++ b/src/plugins/data/public/search/errors/utils.ts @@ -26,6 +26,10 @@ export function getFailedShards(err: IEsError) { return failedShards ? failedShards[0] : undefined; } +export function getTopLevelCause(err: IEsError) { + return err.body?.attributes?.error; +} + export function getRootCause(err: IEsError) { return getFailedShards(err)?.reason; }