Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ML] DataFrame Analytics: ensure clear error when index pattern missing #79378

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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