diff --git a/src/services/NotificationService.ts b/src/services/NotificationService.ts index 1a66870..1c16c84 100644 --- a/src/services/NotificationService.ts +++ b/src/services/NotificationService.ts @@ -72,23 +72,28 @@ export class NotificationService { return this._lastRefreshedTimeMs && Date.now() - this._lastRefreshedTimeMs < thirtyMinutesMs; } - private async sendEtaNotificationImmediately({ deviceId, shuttleId, stopId }: ScheduledNotificationData): Promise { + private async sendEtaNotificationImmediately(notificationData: ScheduledNotificationData): Promise { + const { deviceId, shuttleId, stopId } = notificationData; this.reloadAPNsTokenIfTimePassed(); const url = NotificationService.getAPNsFullUrlToUse(deviceId); const shuttle = await this.repository.getShuttleById(shuttleId); const stop = await this.repository.getStopById(stopId); const eta = await this.repository.getEtaForShuttleAndStopId(shuttleId, stopId); - // TODO: add more specific errors if (!shuttle) { - throw new Error("The shuttle given by the provided shuttleID doesn't exist."); + console.warn(`Notification ${notificationData} fell through; no associated shuttle`); + return false; } if (!stop) { - throw new Error("The shuttle given by the provided stopId doesn't exist."); + console.warn(`Notification ${notificationData} fell through; no associated stop`); + return false; } - // TODO: account for cases where ETA may not exist due to "data race" with ApiBasedRepositoryLoader + + // Notification may not be sent if ETA is unavailable at the moment; + // this is fine because it will be sent again when ETA becomes available if (!eta) { - throw new Error("There is no ETA for this shuttle/stop."); + console.warn(`Notification ${notificationData} fell through; no associated ETA`); + return false; } // Send the fetch request