Modern Apps git

← Modern-Apps.git

shop: unknown server errors are HTTP errors, not 'needs the merchant website'

Commit
856df436f8adc681c5757fba9435807f4e7532f9
Author
Vayun Mathur <[email protected]>
When
2026-11-01 17:51 UTC (1 month ago)
Parents
caac270

Diff

shop/src/main/java/com/vayunmathur/shop/network/ShopBackend.kt
diff --git a/shop/src/main/java/com/vayunmathur/shop/network/ShopBackend.kt b/shop/src/main/java/com/vayunmathur/shop/network/ShopBackend.ktindex 04fdd79704..8f9c90e30b 100644--- a/shop/src/main/java/com/vayunmathur/shop/network/ShopBackend.kt+++ b/shop/src/main/java/com/vayunmathur/shop/network/ShopBackend.kt@@ -178,8 +178,9 @@ internal object ShopHttpBackend : ShopBackend {                     "malformed" -> UcpError.Malformed(envelope.message.ifBlank { "The store sent an unexpected response. Please try again." })                     "rpc" -> UcpError.Rpc(envelope.message.ifBlank { "The merchant couldn't process the request." })                     "uncertain" -> UcpError.Transport("The request may have reached the merchant. Do not retry; check the session or use its website.")-                    // "unsupported" and anything unknown: the merchant website is the fallback.-                    else -> UcpError.Unsupported(envelope.message.ifBlank { "These requirements need the merchant website." })+                    "unsupported" -> UcpError.Unsupported(envelope.message.ifBlank { "These requirements need the merchant website." })+                    // Unknown or empty envelopes (e.g. a proxy error page) say nothing about the merchant.+                    else -> UcpError.Http(status, envelope.message)                 },             )         }
shop/src/test/java/com/vayunmathur/shop/network/ShopBackendTest.kt
diff --git a/shop/src/test/java/com/vayunmathur/shop/network/ShopBackendTest.kt b/shop/src/test/java/com/vayunmathur/shop/network/ShopBackendTest.ktindex 593ca613b2..b012eb4d63 100644--- a/shop/src/test/java/com/vayunmathur/shop/network/ShopBackendTest.kt+++ b/shop/src/test/java/com/vayunmathur/shop/network/ShopBackendTest.kt@@ -124,8 +124,10 @@ class ShopBackendTest {         assertIs<UcpError.Rpc>(errorFor("rpc", 502))         assertIs<UcpError.Malformed>(errorFor("malformed", 400))         assertIs<UcpError.Http>(errorFor("http", 502))-        // Unknown codes fall back to the merchant website.-        assertIs<UcpError.Unsupported>(errorFor("something_new", 503))+        // Unknown codes and envelope-less JSON (e.g. a proxy error page) are plain HTTP errors.+        assertIs<UcpError.Http>(errorFor("something_new", 503))+        stub(BackendRawResponse(502, """{"title":"Bad gateway"}""", emptyMap(), null))+        assertIs<UcpError.Http>((ShopHttpBackend.search("trail").exceptionOrNull() as? ShopBackendException)?.error)         return@runBlocking     }