Skip to content

Commit ea8086b

Browse files
[ML] Improving client side error handling (#76743)
* [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]>
1 parent 22b4e40 commit ea8086b

File tree

61 files changed

+591
-939
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+591
-939
lines changed

x-pack/plugins/ml/common/types/data_frame_analytics.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import { CustomHttpResponseOptions, ResponseError } from 'kibana/server';
7+
import Boom from 'boom';
8+
import { EsErrorBody } from '../util/errors';
89

910
export interface DeleteDataFrameAnalyticsWithIndexStatus {
1011
success: boolean;
11-
error?: CustomHttpResponseOptions<ResponseError>;
12+
error?: EsErrorBody | Boom;
1213
}
1314

1415
export type IndexName = string;

x-pack/plugins/ml/common/util/errors.test.ts

Lines changed: 0 additions & 80 deletions
This file was deleted.

x-pack/plugins/ml/common/util/errors.ts

Lines changed: 0 additions & 177 deletions
This file was deleted.
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import Boom from 'boom';
8+
9+
import { extractErrorMessage, MLHttpFetchError, MLResponseError, EsErrorBody } from './index';
10+
11+
describe('ML - error message utils', () => {
12+
describe('extractErrorMessage', () => {
13+
test('returns just the error message', () => {
14+
const testMsg = 'Saved object [index-pattern/indexpattern] not found';
15+
16+
// bad error, return empty string
17+
const badError = {} as any;
18+
expect(extractErrorMessage(badError)).toBe('');
19+
20+
// raw es error
21+
const esErrorMsg: EsErrorBody = {
22+
error: {
23+
root_cause: [
24+
{
25+
type: 'type',
26+
reason: 'reason',
27+
},
28+
],
29+
type: 'type',
30+
reason: testMsg,
31+
},
32+
status: 404,
33+
};
34+
expect(extractErrorMessage(esErrorMsg)).toBe(testMsg);
35+
36+
// error is basic string
37+
const stringMessage = testMsg;
38+
expect(extractErrorMessage(stringMessage)).toBe(testMsg);
39+
40+
// kibana error without attributes
41+
const bodyWithoutAttributes: MLHttpFetchError<MLResponseError> = {
42+
name: 'name',
43+
req: {} as Request,
44+
request: {} as Request,
45+
message: 'Something else',
46+
body: {
47+
statusCode: 404,
48+
error: 'error',
49+
message: testMsg,
50+
},
51+
};
52+
expect(extractErrorMessage(bodyWithoutAttributes)).toBe(testMsg);
53+
54+
// kibana error with attributes
55+
const bodyWithAttributes: MLHttpFetchError<MLResponseError> = {
56+
name: 'name',
57+
req: {} as Request,
58+
request: {} as Request,
59+
message: 'Something else',
60+
body: {
61+
statusCode: 404,
62+
error: 'error',
63+
message: 'Something else',
64+
attributes: {
65+
body: {
66+
status: 404,
67+
error: {
68+
reason: testMsg,
69+
type: 'type',
70+
root_cause: [{ type: 'type', reason: 'reason' }],
71+
},
72+
},
73+
},
74+
},
75+
};
76+
expect(extractErrorMessage(bodyWithAttributes)).toBe(testMsg);
77+
78+
// boom error
79+
const boomError: Boom<any> = {
80+
message: '',
81+
reformat: () => '',
82+
name: '',
83+
data: [],
84+
isBoom: true,
85+
isServer: false,
86+
output: {
87+
statusCode: 404,
88+
payload: {
89+
statusCode: 404,
90+
error: testMsg,
91+
message: testMsg,
92+
},
93+
headers: {},
94+
},
95+
};
96+
expect(extractErrorMessage(boomError)).toBe(testMsg);
97+
});
98+
});
99+
});
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
export { MLRequestFailure } from './request_error';
8+
export { extractErrorMessage, extractErrorProperties } from './process_errors';
9+
export {
10+
ErrorType,
11+
EsErrorBody,
12+
EsErrorRootCause,
13+
MLErrorObject,
14+
MLHttpFetchError,
15+
MLResponseError,
16+
isBoomError,
17+
isErrorString,
18+
isEsErrorBody,
19+
isMLResponseError,
20+
} from './types';

0 commit comments

Comments
 (0)