Commit 0320100 1 parent b019ef9 commit 0320100 Copy full SHA for 0320100
File tree 3 files changed +81
-22
lines changed
x-pack/plugins/alerting/server/lib/errors
3 files changed +81
-22
lines changed Original file line number Diff line number Diff line change @@ -42,5 +42,71 @@ describe('ES error parser', () => {
42
42
} ,
43
43
} )
44
44
) . toStrictEqual ( ', caused by: "reason2"' ) ;
45
+
46
+ expect (
47
+ getEsErrorMessage ( {
48
+ name : '' ,
49
+ message : '' ,
50
+ meta : {
51
+ body : {
52
+ error : {
53
+ caused_by : {
54
+ reason : 'reason3' ,
55
+ caused_by : {
56
+ reason : 'reason4' ,
57
+ } ,
58
+ } ,
59
+ } ,
60
+ } ,
61
+ } ,
62
+ } )
63
+ ) . toStrictEqual ( ', caused by: "reason3,reason4"' ) ;
64
+
65
+ expect (
66
+ getEsErrorMessage ( {
67
+ name : '' ,
68
+ message : '' ,
69
+ meta : {
70
+ body : {
71
+ error : {
72
+ failed_shards : [
73
+ {
74
+ reason : {
75
+ caused_by : {
76
+ reason : 'reason4' ,
77
+ } ,
78
+ } ,
79
+ } ,
80
+ ] ,
81
+ } ,
82
+ } ,
83
+ } ,
84
+ } )
85
+ ) . toStrictEqual ( ', caused by: "reason4"' ) ;
86
+
87
+ expect (
88
+ getEsErrorMessage ( {
89
+ name : '' ,
90
+ message : '' ,
91
+ meta : {
92
+ body : {
93
+ error : {
94
+ failed_shards : [
95
+ {
96
+ reason : {
97
+ caused_by : {
98
+ reason : 'reason5' ,
99
+ caused_by : {
100
+ reason : 'reason6' ,
101
+ } ,
102
+ } ,
103
+ } ,
104
+ } ,
105
+ ] ,
106
+ } ,
107
+ } ,
108
+ } ,
109
+ } )
110
+ ) . toStrictEqual ( ', caused by: "reason5,reason6"' ) ;
45
111
} ) ;
46
112
} ) ;
Original file line number Diff line number Diff line change 6
6
*/
7
7
8
8
// import { ResponseError } from '@elastic/elasticsearch/lib/errors';
9
- import { ElasticsearchError } from './' ;
9
+ import { ElasticsearchError , ElasticsearchErrorCausedByObject } from './types ' ;
10
10
11
- interface ErrorObject {
12
- caused_by ?: {
13
- reason ?: string ;
14
- caused_by ?: { } ;
15
- } ;
16
- failed_shards ?: Array < {
17
- reason ?: {
18
- caused_by ?: {
19
- reason ?: string ;
20
- } ;
21
- } ;
22
- } > ;
23
- }
24
-
25
- const getEsCause = ( obj : ErrorObject = { } , causes : string [ ] = [ ] ) : string [ ] => {
11
+ const getEsCause = (
12
+ obj : ElasticsearchErrorCausedByObject = { } ,
13
+ causes : string [ ] = [ ]
14
+ ) : string [ ] => {
26
15
const updated = [ ...causes ] ;
27
16
28
17
if ( obj . caused_by ) {
@@ -49,7 +38,7 @@ export const getEsErrorMessage = (error: ElasticsearchError) => {
49
38
let message = error ?. message ;
50
39
const apiError = error ?. error ?. meta ?. body ?. error ?? error ?. meta ?. body ?. error ;
51
40
if ( apiError ) {
52
- message += `, caused by: "${ getEsCause ( apiError as ErrorObject ) } "` ;
41
+ message += `, caused by: "${ getEsCause ( apiError as ElasticsearchErrorCausedByObject ) } "` ;
53
42
}
54
43
return message ;
55
44
} ;
Original file line number Diff line number Diff line change @@ -10,15 +10,19 @@ export interface ErrorThatHandlesItsOwnResponse extends Error {
10
10
sendResponse ( res : KibanaResponseFactory ) : IKibanaResponse ;
11
11
}
12
12
13
- interface ElasticsearchErrorCausedBy {
14
- caused_by ?: {
15
- reason ?: string ;
16
- } ;
13
+ export interface ElasticsearchErrorCausedByObject {
14
+ reason ?: string ;
15
+ caused_by ?: ElasticsearchErrorCausedByObject ;
16
+ failed_shards ?: Array < {
17
+ reason ?: {
18
+ caused_by ?: ElasticsearchErrorCausedByObject ;
19
+ } ;
20
+ } > ;
17
21
}
18
22
19
23
interface ElasticsearchErrorMeta {
20
24
body ?: {
21
- error ?: ElasticsearchErrorCausedBy ;
25
+ error ?: ElasticsearchErrorCausedByObject ;
22
26
} ;
23
27
}
24
28
You can’t perform that action at this time.
0 commit comments