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] Improving client side error handling #76743

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
5 changes: 3 additions & 2 deletions x-pack/plugins/ml/common/types/data_frame_analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { CustomHttpResponseOptions, ResponseError } from 'kibana/server';
import Boom from 'boom';
import { EsErrorBody } from '../util/errors';

export interface DeleteDataFrameAnalyticsWithIndexStatus {
success: boolean;
error?: CustomHttpResponseOptions<ResponseError>;
error?: EsErrorBody | Boom;
}

export type IndexName = string;
Expand Down
80 changes: 0 additions & 80 deletions x-pack/plugins/ml/common/util/errors.test.ts

This file was deleted.

177 changes: 0 additions & 177 deletions x-pack/plugins/ml/common/util/errors.ts

This file was deleted.

99 changes: 99 additions & 0 deletions x-pack/plugins/ml/common/util/errors/errors.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import Boom from 'boom';

import { extractErrorMessage, MLHttpFetchError, MLResponseError, EsErrorBody } from './index';

describe('ML - error message utils', () => {
describe('extractErrorMessage', () => {
test('returns just the error message', () => {
const testMsg = 'Saved object [index-pattern/indexpattern] not found';

// bad error, return empty string
const badError = {} as any;
expect(extractErrorMessage(badError)).toBe('');

// raw es error
const esErrorMsg: EsErrorBody = {
error: {
root_cause: [
{
type: 'type',
reason: 'reason',
},
],
type: 'type',
reason: testMsg,
},
status: 404,
};
expect(extractErrorMessage(esErrorMsg)).toBe(testMsg);

// error is basic string
const stringMessage = testMsg;
expect(extractErrorMessage(stringMessage)).toBe(testMsg);

// kibana error without attributes
const bodyWithoutAttributes: MLHttpFetchError<MLResponseError> = {
name: 'name',
req: {} as Request,
request: {} as Request,
message: 'Something else',
body: {
statusCode: 404,
error: 'error',
message: testMsg,
},
};
expect(extractErrorMessage(bodyWithoutAttributes)).toBe(testMsg);

// kibana error with attributes
const bodyWithAttributes: MLHttpFetchError<MLResponseError> = {
name: 'name',
req: {} as Request,
request: {} as Request,
message: 'Something else',
body: {
statusCode: 404,
error: 'error',
message: 'Something else',
attributes: {
body: {
status: 404,
error: {
reason: testMsg,
type: 'type',
root_cause: [{ type: 'type', reason: 'reason' }],
},
},
},
},
};
expect(extractErrorMessage(bodyWithAttributes)).toBe(testMsg);

// boom error
const boomError: Boom<any> = {
message: '',
reformat: () => '',
name: '',
data: [],
isBoom: true,
isServer: false,
output: {
statusCode: 404,
payload: {
statusCode: 404,
error: testMsg,
message: testMsg,
},
headers: {},
},
};
expect(extractErrorMessage(boomError)).toBe(testMsg);
});
});
});
20 changes: 20 additions & 0 deletions x-pack/plugins/ml/common/util/errors/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

export { MLRequestFailure } from './request_error';
export { extractErrorMessage, extractErrorProperties } from './process_errors';
export {
ErrorType,
EsErrorBody,
EsErrorRootCause,
MLErrorObject,
MLHttpFetchError,
MLResponseError,
isBoomError,
isErrorString,
isEsErrorBody,
isMLResponseError,
} from './types';
Loading