Skip to content

Commit

Permalink
[ML] Improving client side error handling (#76743)
Browse files Browse the repository at this point in the history
* [ML] Improving client side error handling

* adding stacktrace to request errors

* copying error parsing to transforms

* update snapshot

* fixing jest tests

* adding test and removing debug log output

* updating translations

* rewriting error extracting code

* fixing tests

* removing message bar service

* removing test code

* updating translations

* combining job creation error handling

* refactoring error files

* updating test

* fixing bug in DFA deletion

* improving mml warning

Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
jgowdyelastic and elasticmachine authored Sep 11, 2020
1 parent 22b4e40 commit ea8086b
Show file tree
Hide file tree
Showing 61 changed files with 591 additions and 939 deletions.
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

0 comments on commit ea8086b

Please sign in to comment.