Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Treat malformed HTTP responses as connection errors (#63)
By default, OkHTTP would throw an IOException when an illegal HTTP response is returned, which is an unexpected exception. This PR replaces that exception with java.net.ConnectException, which we catch and wrap with a PoWeb `ServerConnectionException`, which provides more useful information. Before: ``` java.io.IOException: unexpected end of stream on http://127.0.0.1:13276/... at okhttp3.internal.http1.Http1ExchangeCodec.readResponseHeaders(Http1ExchangeCodec.kt:202) (...) Caused by: java.io.EOFException: \n not found: limit=0 content=… at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.kt:348) (...) ``` [Now](https://console.firebase.google.com/u/0/project/relaynet-gateway-android/testlab/histories/bh.fce322cdd2254629/matrices/6474453305210171425/executions/bs.a50e5565a3e74f36/testcases/5/test-cases), using relaycorp/relaynet-gateway-android@731ab77: ``` tech.relaycorp.poweb.ServerConnectionException: Failed to connect to http://127.0.0.1:13276/v1/parcels (...) Caused by: java.net.ConnectException: Failed to connect to /127.0.0.1:13276 (...) Caused by: java.net.ConnectException: failed to connect to /127.0.0.1 (port 13276) from /127.0.0.1 (port 43068) after 10000ms: (...) Caused by: android.system.ErrnoException: isConnected failed: ECONNREFUSED (Connection refused) ```
- Loading branch information