66 */
77
88import Boom from '@hapi/boom' ;
9- import { SavedObjectsFindResponse , SavedObject } from 'kibana/server' ;
9+ import { SavedObjectsFindResponse , SavedObject , Logger } from 'kibana/server' ;
1010
1111import {
1212 ActionConnector ,
@@ -22,26 +22,16 @@ import {
2222import { buildCaseUserActionItem } from '../../services/user_actions/helpers' ;
2323
2424import { createIncident , getCommentContextFromAttributes } from './utils' ;
25- import { createCaseError , flattenCaseSavedObject , getAlertInfoFromComments } from '../../common' ;
25+ import {
26+ AlertInfo ,
27+ createCaseError ,
28+ flattenCaseSavedObject ,
29+ getAlertInfoFromComments ,
30+ } from '../../common' ;
2631import { CasesClient , CasesClientArgs , CasesClientInternal } from '..' ;
2732import { Operations } from '../../authorization' ;
2833import { casesConnectors } from '../../connectors' ;
29-
30- /**
31- * Returns true if the case should be closed based on the configuration settings and whether the case
32- * is a collection. Collections are not closable because we aren't allowing their status to be changed.
33- * In the future we could allow push to close all the sub cases of a collection but that's not currently supported.
34- */
35- function shouldCloseByPush (
36- configureSettings : SavedObjectsFindResponse < CasesConfigureAttributes > ,
37- caseInfo : SavedObject < CaseAttributes >
38- ) : boolean {
39- return (
40- configureSettings . total > 0 &&
41- configureSettings . saved_objects [ 0 ] . attributes . closure_type === 'close-by-pushing' &&
42- caseInfo . attributes . type !== CaseType . collection
43- ) ;
44- }
34+ import { CasesClientGetAlertsResponse } from '../alerts/types' ;
4535
4636/**
4737 * Parameters for pushing a case to an external system
@@ -106,9 +96,7 @@ export const push = async (
10696
10797 const alertsInfo = getAlertInfoFromComments ( theCase ?. comments ) ;
10898
109- const alerts = await casesClientInternal . alerts . get ( {
110- alertsInfo,
111- } ) ;
99+ const alerts = await getAlertsCatchErrors ( { casesClientInternal, alertsInfo, logger } ) ;
112100
113101 const getMappingsResponse = await casesClientInternal . configuration . getMappings ( {
114102 connector : theCase . connector ,
@@ -278,3 +266,38 @@ export const push = async (
278266 throw createCaseError ( { message : `Failed to push case: ${ error } ` , error, logger } ) ;
279267 }
280268} ;
269+
270+ async function getAlertsCatchErrors ( {
271+ casesClientInternal,
272+ alertsInfo,
273+ logger,
274+ } : {
275+ casesClientInternal : CasesClientInternal ;
276+ alertsInfo : AlertInfo [ ] ;
277+ logger : Logger ;
278+ } ) : Promise < CasesClientGetAlertsResponse > {
279+ try {
280+ return await casesClientInternal . alerts . get ( {
281+ alertsInfo,
282+ } ) ;
283+ } catch ( error ) {
284+ logger . error ( `Failed to retrieve alerts during push: ${ error } ` ) ;
285+ return [ ] ;
286+ }
287+ }
288+
289+ /**
290+ * Returns true if the case should be closed based on the configuration settings and whether the case
291+ * is a collection. Collections are not closable because we aren't allowing their status to be changed.
292+ * In the future we could allow push to close all the sub cases of a collection but that's not currently supported.
293+ */
294+ function shouldCloseByPush (
295+ configureSettings : SavedObjectsFindResponse < CasesConfigureAttributes > ,
296+ caseInfo : SavedObject < CaseAttributes >
297+ ) : boolean {
298+ return (
299+ configureSettings . total > 0 &&
300+ configureSettings . saved_objects [ 0 ] . attributes . closure_type === 'close-by-pushing' &&
301+ caseInfo . attributes . type !== CaseType . collection
302+ ) ;
303+ }
0 commit comments