change behavior for missing shuttle/stop/ETA

This commit is contained in:
2025-02-03 23:29:01 -08:00
parent 6473661607
commit 80e976752b

View File

@@ -72,23 +72,28 @@ export class NotificationService {
return this._lastRefreshedTimeMs && Date.now() - this._lastRefreshedTimeMs < thirtyMinutesMs;
}
private async sendEtaNotificationImmediately({ deviceId, shuttleId, stopId }: ScheduledNotificationData): Promise<boolean> {
private async sendEtaNotificationImmediately(notificationData: ScheduledNotificationData): Promise<boolean> {
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