Skip to content

Commit

Permalink
ensure missing indexPattern error is bubbled up to error callout (#79378
Browse files Browse the repository at this point in the history
) (#79664)
  • Loading branch information
alvarezmelissa87 authored Oct 6, 2020
1 parent ffaa26e commit 003eaad
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions x-pack/plugins/ml/common/util/errors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export { MLRequestFailure } from './request_error';
export { extractErrorMessage, extractErrorProperties } from './process_errors';
export {
ErrorType,
ErrorMessage,
EsErrorBody,
EsErrorRootCause,
MLErrorObject,
Expand Down
9 changes: 8 additions & 1 deletion x-pack/plugins/ml/common/util/errors/process_errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
MLErrorObject,
isBoomError,
isErrorString,
isErrorMessage,
isEsErrorBody,
isMLResponseError,
} from './types';
Expand Down Expand Up @@ -40,7 +41,7 @@ export const extractErrorProperties = (error: ErrorType): MLErrorObject => {
};
}

if (error?.body === undefined) {
if (error?.body === undefined && !error?.message) {
return {
message: '',
};
Expand Down Expand Up @@ -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: '',
Expand Down
8 changes: 8 additions & 0 deletions x-pack/plugins/ml/common/util/errors/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ export interface MLResponseError {
};
}

export interface ErrorMessage {
message: string;
}

export interface MLErrorObject {
message: string;
statusCode?: number;
Expand All @@ -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;
}
Expand Down

0 comments on commit 003eaad

Please sign in to comment.