Skip to content

Commit

Permalink
add basic error handling to network driver
Browse files Browse the repository at this point in the history
  • Loading branch information
Funkatronics committed Feb 6, 2023
1 parent 3deab25 commit 95a84d5
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

0 comments on commit 95a84d5

Please sign in to comment.