@@ -276,7 +276,7 @@ export class SessionIndex {
276276 }
277277
278278 const sessionIndexTemplateName = `${ this . options . kibanaIndexName } _security_session_index_template_${ SESSION_INDEX_TEMPLATE_VERSION } ` ;
279- return ( this . indexInitialization = new Promise ( async ( resolve ) => {
279+ return ( this . indexInitialization = new Promise < void > ( async ( resolve , reject ) => {
280280 // Check if required index template exists.
281281 let indexTemplateExists = false ;
282282 try {
@@ -288,7 +288,7 @@ export class SessionIndex {
288288 this . options . logger . error (
289289 `Failed to check if session index template exists: ${ err . message } `
290290 ) ;
291- throw err ;
291+ return reject ( err ) ;
292292 }
293293
294294 // Create index template if it doesn't exist.
@@ -303,7 +303,7 @@ export class SessionIndex {
303303 this . options . logger . debug ( 'Successfully created session index template.' ) ;
304304 } catch ( err ) {
305305 this . options . logger . error ( `Failed to create session index template: ${ err . message } ` ) ;
306- throw err ;
306+ return reject ( err ) ;
307307 }
308308 }
309309
@@ -316,7 +316,7 @@ export class SessionIndex {
316316 } ) ;
317317 } catch ( err ) {
318318 this . options . logger . error ( `Failed to check if session index exists: ${ err . message } ` ) ;
319- throw err ;
319+ return reject ( err ) ;
320320 }
321321
322322 // Create index if it doesn't exist.
@@ -334,13 +334,14 @@ export class SessionIndex {
334334 this . options . logger . debug ( 'Session index already exists.' ) ;
335335 } else {
336336 this . options . logger . error ( `Failed to create session index: ${ err . message } ` ) ;
337- throw err ;
337+ return reject ( err ) ;
338338 }
339339 }
340340 }
341341
342342 // Notify any consumers that are awaiting on this promise and immediately reset it.
343343 resolve ( ) ;
344+ } ) . finally ( ( ) => {
344345 this . indexInitialization = undefined ;
345346 } ) ) ;
346347 }
0 commit comments