From 3a88831148eaeb18729474903a03456c2125c04c Mon Sep 17 00:00:00 2001 From: Collin Duncan <3679940+cgduncan7@users.noreply.github.com> Date: Wed, 20 Mar 2024 20:43:37 +0100 Subject: [PATCH] Implementing multiple attempts or failing early if courts are full --- src/reservations/worker.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/reservations/worker.ts b/src/reservations/worker.ts index b94be68..f2e3581 100644 --- a/src/reservations/worker.ts +++ b/src/reservations/worker.ts @@ -51,12 +51,14 @@ export class ReservationsWorker { reservation: Reservation, attemptsMade: number, ) { - if (error instanceof NoCourtAvailableError) { + const shouldWaitlist = error instanceof NoCourtAvailableError + if (shouldWaitlist) { this.loggerService.warn('No court available') + } else { + this.loggerService.error('Error while performing reservation', error) } - this.loggerService.error('Error while performing reservation', error) if ( - attemptsMade === DAILY_RESERVATIONS_ATTEMPTS && + (shouldWaitlist || attemptsMade === DAILY_RESERVATIONS_ATTEMPTS) && !reservation.waitListed ) { this.loggerService.log('Adding reservation to waiting list') @@ -66,6 +68,8 @@ export class ReservationsWorker { reservation.dateRangeEnd, ) await this.brService.addReservationToWaitList(reservation) + } else { + throw error } }