55 * 2.0.
66 */
77
8- import Boom from '@hapi/boom' ;
8+ import Boom , { isBoom , Boom as BoomType } from '@hapi/boom' ;
99
1010import { SavedObjectsBulkUpdateResponse , SavedObjectsUpdateResponse } from 'kibana/server' ;
1111import { flattenCaseSavedObject } from '../../routes/api/utils' ;
@@ -24,6 +24,16 @@ import { buildCaseUserActionItem } from '../../services/user_actions/helpers';
2424import { CaseClientPush , CaseClientFactoryArguments } from '../types' ;
2525import { createIncident , getCommentContextFromAttributes , isCommentAlertType } from './utils' ;
2626
27+ const createError = ( e : Error | BoomType , message : string ) : Error | BoomType => {
28+ if ( isBoom ( e ) ) {
29+ e . message = message ;
30+ e . output . payload . message = message ;
31+ return e ;
32+ }
33+
34+ return Error ( message ) ;
35+ } ;
36+
2737export const push = ( {
2838 savedObjectsClient,
2939 caseService,
@@ -52,7 +62,8 @@ export const push = ({
5262 caseClient . getUserActions ( { caseId } ) ,
5363 ] ) ;
5464 } catch ( e ) {
55- throw new Error ( `Error getting case and/or connector and/or user actions: ${ e . message } ` ) ;
65+ const message = `Error getting case and/or connector and/or user actions: ${ e . message } ` ;
66+ throw createError ( e , message ) ;
5667 }
5768
5869 // We need to change the logic when we support subcases
@@ -78,11 +89,8 @@ export const push = ({
7889 connectorType : connector . actionTypeId ,
7990 } ) ;
8091 } catch ( e ) {
81- throw new Error (
82- e . isBoom
83- ? e . output . payload . message
84- : `Error getting mapping for connector with id ${ connector . id } : ${ e . message } `
85- ) ;
92+ const message = `Error getting mapping for connector with id ${ connector . id } : ${ e . message } ` ;
93+ throw createError ( e , message ) ;
8694 }
8795
8896 try {
@@ -95,7 +103,8 @@ export const push = ({
95103 alerts,
96104 } ) ;
97105 } catch ( e ) {
98- throw new Error ( `Error creating incident for case with id ${ theCase . id } : ${ e . message } ` ) ;
106+ const message = `Error creating incident for case with id ${ theCase . id } : ${ e . message } ` ;
107+ throw createError ( e , message ) ;
99108 }
100109
101110 const pushRes = await actionsClient . execute ( {
@@ -139,9 +148,8 @@ export const push = ({
139148 } ) ,
140149 ] ) ;
141150 } catch ( e ) {
142- throw new Error (
143- `Error getting user and/or case and/or case configuration and/or case comments: ${ e . message } `
144- ) ;
151+ const message = `Error getting user and/or case and/or case configuration and/or case comments: ${ e . message } ` ;
152+ throw createError ( e , message ) ;
145153 }
146154
147155 // eslint-disable-next-line @typescript-eslint/naming-convention
@@ -226,9 +234,8 @@ export const push = ({
226234 } ) ,
227235 ] ) ;
228236 } catch ( e ) {
229- throw new Error (
230- `Error updating case and/or comments and/or creating user action: ${ e . message } `
231- ) ;
237+ const message = `Error updating case and/or comments and/or creating user action: ${ e . message } ` ;
238+ throw createError ( e , message ) ;
232239 }
233240 /* End of update case with push information */
234241
0 commit comments