Skip to content

Commit b935426

Browse files
committed
Handle multiple types here
1 parent f9a8aea commit b935426

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

x-pack/plugins/alerting/server/lib/errors/es_error_parser.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,11 @@ const getEsCause = (obj: ErrorObject = {}, causes: string[] = []): string[] => {
4747

4848
export const getEsErrorMessage = (error: Error) => {
4949
let message = error.message;
50-
const apiError = (error as ElasticsearchError)?.meta?.body?.error;
50+
const apiError =
51+
(error as ElasticsearchError)?.error?.meta?.body?.error ??
52+
(error as ElasticsearchError)?.meta?.body?.error;
5153
if (apiError) {
52-
console.log({ apiError });
5354
message += `, caused by: "${getEsCause(apiError as ErrorObject)}"`;
54-
} else {
55-
console.log({ error });
5655
}
5756
return message;
5857
};

x-pack/plugins/alerting/server/lib/errors/types.ts

+9-5
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@ export interface ErrorThatHandlesItsOwnResponse extends Error {
1111
sendResponse(res: KibanaResponseFactory): IKibanaResponse;
1212
}
1313

14+
interface ElasticsearchErrorMeta {
15+
body?: {
16+
error?: ApiError;
17+
};
18+
}
19+
1420
export interface ElasticsearchError extends Error {
15-
// error?: ApiError;
16-
meta?: {
17-
body?: {
18-
error?: ApiError;
19-
};
21+
error?: {
22+
meta?: ElasticsearchErrorMeta;
2023
};
24+
meta?: ElasticsearchErrorMeta;
2125
}

0 commit comments

Comments
 (0)