@@ -430,9 +430,9 @@ async function handler(req: CustomRequest) {
430430 bookingToDelete . recurringEventId &&
431431 allRemainingBookings
432432 ) {
433- bookingToDelete . user . credentials
433+ const promises = bookingToDelete . user . credentials
434434 . filter ( ( credential ) => credential . type . endsWith ( "_calendar" ) )
435- . forEach ( async ( credential ) => {
435+ . map ( async ( credential ) => {
436436 const calendar = await getCalendar ( credential ) ;
437437 for ( const updBooking of updatedBookings ) {
438438 const bookingRef = updBooking . references . find ( ( ref ) => ref . type . includes ( "_calendar" ) ) ;
@@ -443,6 +443,13 @@ async function handler(req: CustomRequest) {
443443 }
444444 }
445445 } ) ;
446+ try {
447+ await Promise . all ( promises ) ;
448+ } catch ( error ) {
449+ if ( error instanceof Error ) {
450+ logger . error ( error . message ) ;
451+ }
452+ }
446453 } else {
447454 apiDeletes . push ( calendar ?. deleteEvent ( uid , evt , externalCalendarId ) as Promise < unknown > ) ;
448455 }
@@ -603,11 +610,13 @@ async function handler(req: CustomRequest) {
603610 } ) ;
604611
605612 // delete scheduled jobs of cancelled bookings
613+ // FIXME: async calls into ether
606614 updatedBookings . forEach ( ( booking ) => {
607615 cancelScheduledJobs ( booking ) ;
608616 } ) ;
609617
610618 //Workflows - cancel all reminders for cancelled bookings
619+ // FIXME: async calls into ether
611620 updatedBookings . forEach ( ( booking ) => {
612621 booking . workflowReminders . forEach ( ( reminder ) => {
613622 if ( reminder . method === WorkflowMethods . EMAIL ) {
@@ -622,11 +631,14 @@ async function handler(req: CustomRequest) {
622631
623632 const prismaPromises : Promise < unknown > [ ] = [ bookingReferenceDeletes ] ;
624633
625- // @TODO : find a way in the future if a promise fails don't stop the rest of the promises
626- // Also if emails fails try to requeue them
627634 try {
628- await Promise . all ( prismaPromises . concat ( apiDeletes ) ) ;
635+ const settled = await Promise . allSettled ( prismaPromises . concat ( apiDeletes ) ) ;
636+ const rejected = settled . filter ( ( { status } ) => status === "rejected" ) as PromiseRejectedResult [ ] ;
637+ if ( rejected . length ) {
638+ throw new Error ( `Reasons: ${ rejected . map ( ( { reason } ) => reason ) } ` ) ;
639+ }
629640
641+ // TODO: if emails fail try to requeue them
630642 await sendCancelledEmails ( evt , { eventName : bookingToDelete ?. eventType ?. eventName } ) ;
631643 } catch ( error ) {
632644 console . error ( "Error deleting event" , error ) ;
0 commit comments