From 9794188cbf5eefb530b4a87197113b3ad220cf66 Mon Sep 17 00:00:00 2001 From: Melissa Alvarez Date: Tue, 6 Oct 2020 09:39:42 -0400 Subject: [PATCH] ensure missing indexPattern error is bubbled up to error callout (#79378) --- x-pack/plugins/ml/common/util/errors/index.ts | 1 + x-pack/plugins/ml/common/util/errors/process_errors.ts | 9 ++++++++- x-pack/plugins/ml/common/util/errors/types.ts | 8 ++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/ml/common/util/errors/index.ts b/x-pack/plugins/ml/common/util/errors/index.ts index d6d33b86e6fa92..1398c8d8b4135d 100644 --- a/x-pack/plugins/ml/common/util/errors/index.ts +++ b/x-pack/plugins/ml/common/util/errors/index.ts @@ -8,6 +8,7 @@ export { MLRequestFailure } from './request_error'; export { extractErrorMessage, extractErrorProperties } from './process_errors'; export { ErrorType, + ErrorMessage, EsErrorBody, EsErrorRootCause, MLErrorObject, diff --git a/x-pack/plugins/ml/common/util/errors/process_errors.ts b/x-pack/plugins/ml/common/util/errors/process_errors.ts index 4addfa414ef56c..bf8c462e5d2512 100644 --- a/x-pack/plugins/ml/common/util/errors/process_errors.ts +++ b/x-pack/plugins/ml/common/util/errors/process_errors.ts @@ -9,6 +9,7 @@ import { MLErrorObject, isBoomError, isErrorString, + isErrorMessage, isEsErrorBody, isMLResponseError, } from './types'; @@ -40,7 +41,7 @@ export const extractErrorProperties = (error: ErrorType): MLErrorObject => { }; } - if (error?.body === undefined) { + if (error?.body === undefined && !error?.message) { return { message: '', }; @@ -70,6 +71,12 @@ export const extractErrorProperties = (error: ErrorType): MLErrorObject => { } } + if (isErrorMessage(error)) { + return { + message: error.message, + }; + } + // If all else fail return an empty message instead of JSON.stringify return { message: '', diff --git a/x-pack/plugins/ml/common/util/errors/types.ts b/x-pack/plugins/ml/common/util/errors/types.ts index 3d9fc82be8d859..fec35141f1b5ac 100644 --- a/x-pack/plugins/ml/common/util/errors/types.ts +++ b/x-pack/plugins/ml/common/util/errors/types.ts @@ -31,6 +31,10 @@ export interface MLResponseError { }; } +export interface ErrorMessage { + message: string; +} + export interface MLErrorObject { message: string; statusCode?: number; @@ -51,6 +55,10 @@ export function isErrorString(error: any): error is string { return typeof error === 'string'; } +export function isErrorMessage(error: any): error is ErrorMessage { + return error && error.message !== undefined && typeof error.message === 'string'; +} + export function isMLResponseError(error: any): error is MLResponseError { return typeof error.body === 'object' && 'message' in error.body; }