From 95a84d56c3db98f703df0df91c21eba1d63c3e1c Mon Sep 17 00:00:00 2001 From: funkatronics Date: Mon, 6 Feb 2023 11:38:58 -0700 Subject: [PATCH] add basic error handling to network driver --- .../java/com/metaplex/lib/drivers/network/JdkHttpDriver.kt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/src/main/java/com/metaplex/lib/drivers/network/JdkHttpDriver.kt b/lib/src/main/java/com/metaplex/lib/drivers/network/JdkHttpDriver.kt index 3034450..8a2adbd 100644 --- a/lib/src/main/java/com/metaplex/lib/drivers/network/JdkHttpDriver.kt +++ b/lib/src/main/java/com/metaplex/lib/drivers/network/JdkHttpDriver.kt @@ -42,14 +42,17 @@ class JdkHttpDriver : HttpNetworkDriver { } // read response - val responseString = inputStream.bufferedReader().use { it.readText() } + val response = (inputStream ?: errorStream)?.bufferedReader()?.use { + it.readText() + }?.let { responseString -> Result.success(responseString) } + ?: Result.failure(Throwable("No Response")) // TODO: should check response code and/or errorStream for errors // println("URL : $url") // println("Response Code : $responseCode") // println("input stream : $responseString") - continuation.resumeWith(Result.success(responseString)) + continuation.resumeWith(response) } } } \ No newline at end of file