travel: surface server error on confirmCancellation failure
- Commit
2da3a75f6737288b64cbf975e680c903d6955cbd- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-08 02:40 UTC (28 days ago)
- Parents
e0ff19e
When confirming a cancellation failed (server rejection, network error), the code discarded the real throwable and built a synthetic IllegalStateException carrying only "Cancellation failed. Please try again.", so users never saw actionable reasons like a closed cancellation window or an already-cancelled booking. Root cause: getOrNull() in confirmCancellation (util/TravelOrderOps.kt) threw away the failure, and errorMessage() was then fed the synthetic exception instead of the real one. The fix keeps the throwable via getOrElse and shows its message, keeping the cancellation-specific text only as the fallback for blank messages. This matches how quoteCancellation on the line above already reports errorMessage(it). User-visible effect: failed cancellation confirms now explain why instead of always showing the generic retry prompt. Verified with :travel:testDevUnitTest (BUILD SUCCESSFUL).
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 51c35e06d5..c9e9bed3d3 100644--- a/travel/src/main/java/com/vayunmathur/travel/util/TravelOrderOps.kt+++ b/travel/src/main/java/com/vayunmathur/travel/util/TravelOrderOps.kt@@ -122,11 +122,13 @@ fun TravelViewModel.confirmCancellation(orderId: String) { cancellationMutable.value = cancellationMutable.value.copy(confirming = true, error = null) viewModelScope.launch { val stored = repository.getBookedTrip(orderId)- val confirmed = runCatching { TravelOrderApi.confirmCancellation(quote.id) }.getOrNull()- if (confirmed == null) {+ val confirmed = runCatching { TravelOrderApi.confirmCancellation(quote.id) }.getOrElse { cancellationMutable.value = cancellationMutable.value.copy( confirming = false,- error = errorMessage(IllegalStateException("Cancellation failed. Please try again."))+ // Surface the server's reason (e.g. window closed, already+ // cancelled); keep a specific fallback for blank messages.+ error = it.message?.takeIf { msg -> msg.isNotBlank() }+ ?: "Cancellation failed. Please try again." ) return@launch }