travel: keep cancel/change polls alive on transient failure
- Commit
e0ff19eb5db7b7c15eb684b8a87619c187105024- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-08 02:39 UTC (28 days ago)
- Parents
3329c6e
A single failed status read (dropped connection, brief offline blip) aborted the cancellation and change poll loops via getOrNull() ?: return@launch, leaving CancellationState/ChangeState stuck at polling=true forever: the pages show a "processing" message with the confirm button disabled and no error, and nothing ever recovers it short of leaving the screen. Root cause: unlike pollTrip in TravelBookingOps, which skips failed reads and keeps polling, both servicing poll loops treated any network error as terminal but reported nothing. The fix skips the failed round (return@repeat) so polling continues; the existing 20-round limit still bounds the wait and surfaces "Still processing. Check back shortly." on true timeout. User-visible effect: cancelling or changing a trip during flaky connectivity no longer strands the screen on an endless processing state. Verified with :travel:testDevUnitTest (BUILD SUCCESSFUL; no behavior covered by unit tests changes — the loops need a device/network harness — but the module suite stays green).
Diff
travel/src/main/java/com/vayunmathur/travel/util/TravelOrderOps.kt
diff --git a/travel/src/main/java/com/vayunmathur/travel/util/TravelOrderOps.kt b/travel/src/main/java/com/vayunmathur/travel/util/TravelOrderOps.ktindex 6e6c0186f2..51c35e06d5 100644--- a/travel/src/main/java/com/vayunmathur/travel/util/TravelOrderOps.kt+++ b/travel/src/main/java/com/vayunmathur/travel/util/TravelOrderOps.kt@@ -151,7 +151,13 @@ fun TravelViewModel.confirmCancellation(orderId: String) { val ref = stored?.bookingReference.orEmpty() val status = runCatching { TravelOrderApi.cancellationStatus(confirmed.id, ref, stored?.lastName.orEmpty())- }.getOrNull() ?: return@launch+ }.getOrNull()+ if (status == null) {+ // Transient failure: keep polling instead of stranding+ // the UI in polling=true (matches pollTrip); the round+ // limit below still bounds the wait.+ return@repeat+ } if (status.status == "succeeded") { stored?.let { repository.upsertBookedTrip(it.copy(status = TRIP_STATUS_CANCELLED, awaitingPayment = false))@@ -272,7 +278,12 @@ private fun TravelViewModel.pollChangeStatus(ref: String, lastName: String) { repeat(STATUS_POLL_ROUNDS) { round -> if (round > 0) delay(STATUS_POLL_INTERVAL_MS) val status = runCatching { TravelOrderApi.changeStatus(ref, lastName) }.getOrNull()- ?: return@launch+ if (status == null) {+ // Transient failure: keep polling instead of stranding the+ // UI in polling=true (matches pollTrip); the round limit+ // below still bounds the wait.+ return@repeat+ } if (status.status == "confirmed") { changeMutable.value = changeMutable.value.copy(polling = false, done = true) return@launch