From 6a910901e8bab68bd7474dfd14a3edb8fc95c7ae Mon Sep 17 00:00:00 2001 From: Devin Hurley Date: Fri, 17 Jan 2020 13:47:30 -0500 Subject: [PATCH] fix bug where convertToSnakeCase would throw error 'cannot convert null or undefined to object' if passed null --- .../detection_engine/routes/rules/find_rules_status_route.ts | 5 ++++- .../plugins/siem/server/lib/detection_engine/rules/types.ts | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/rules/find_rules_status_route.ts b/x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/rules/find_rules_status_route.ts index ba996c7251d6..01c75079dca0 100644 --- a/x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/rules/find_rules_status_route.ts +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/rules/find_rules_status_route.ts @@ -68,7 +68,10 @@ export const createFindRulesStatusRoute: Hapi.ServerRoute = { return { ...(await acc), [id]: { - current_status: convertToSnakeCase(lastFiveErrorsForId.saved_objects[0].attributes), + current_status: + lastFiveErrorsForId.saved_objects.length > 0 + ? convertToSnakeCase(lastFiveErrorsForId.saved_objects[0].attributes) + : null, failures: lastFiveErrorsForId.saved_objects .slice(1) .map(errorItem => convertToSnakeCase(errorItem.attributes)), diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/types.ts b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/types.ts index 182d9fcfb8cc..86731d2e7cd6 100644 --- a/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/types.ts +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/types.ts @@ -58,8 +58,8 @@ export interface IRuleStatusAttributes { export interface RuleStatusResponse { [key: string]: { - current_status: IRuleStatusAttributes; - failures: IRuleStatusAttributes[]; + current_status: IRuleStatusAttributes | null | undefined; + failures: IRuleStatusAttributes[] | null | undefined; }; }