diff --git a/client/src/main/kotlin/io/flamenet/client/RelayClient.kt b/client/src/main/kotlin/io/flamenet/client/RelayClient.kt index add1f7d..e586028 100644 --- a/client/src/main/kotlin/io/flamenet/client/RelayClient.kt +++ b/client/src/main/kotlin/io/flamenet/client/RelayClient.kt @@ -421,11 +421,26 @@ class RelayClient( val body = response.body?.string().orEmpty() val code = response.code response.close() + + // ⚠️ **Carry the relay's own sentence, not its JSON.** These messages + // reach the screen: creating a group with a member who has never signed + // in showed the user + // + // relay returned 400: {"code":"bad_request","message":"No reachable + // device for user: 30.","data":{"status":400}} + // + // when the relay had written a perfectly readable sentence inside it. + // `MessengerApi.send` and `RelayAccounts` already unwrap `message`; + // this path did not, so which client a feature happened to use decided + // whether its errors were legible. + val readable = runCatching { JSONObject(body).optString("message") } + .getOrNull().orEmpty().ifBlank { body } + throw when (code) { - 401 -> RelayException.Unauthorized(body) + 401 -> RelayException.Unauthorized(readable) 404 -> RelayException.NotFound(path) 429 -> RelayException.RateLimited(response.header("Retry-After")?.toIntOrNull()) - else -> RelayException.Http(code, body) + else -> RelayException.Http(code, readable) } }