Skip to content

Commit

Permalink
Merge pull request #129 from creativedrewy/creativedrewy/networkroute…
Browse files Browse the repository at this point in the history
…r-fix

Fix a small bug in NetworkingRouter
  • Loading branch information
ajamaica authored Aug 9, 2023
2 parents 0f914ea + e9f66b5 commit e19e5a9
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions solana/src/main/java/com/solana/networking/NetworkingRouter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import kotlinx.coroutines.*
import kotlinx.serialization.KSerializer
import kotlinx.serialization.SerializationException
import kotlinx.serialization.json.Json
import java.lang.Exception
import java.net.HttpURLConnection
import kotlin.coroutines.resumeWithException

Expand Down Expand Up @@ -41,26 +42,24 @@ class HttpNetworkingRouter(
)
outputStream.close()

// read response
val responseString = inputStream.bufferedReader().use { it.readText() }
when (responseCode) {
HttpURLConnection.HTTP_OK -> {
try {
val responseString = inputStream.bufferedReader().use { it.readText() }

// TODO: should check response code and/or errorStream for errors
println("URL : $url")
println("Response Code : $responseCode")
println("input stream : $responseString")

try {
val decoded = json.decodeFromString(
RpcResponse.serializer(resultSerializer),
responseString
)
continuation.resumeWith(
Result.success(
decoded
)
)
} catch (e: SerializationException){
continuation.resumeWithException(e)
val decoded = json.decodeFromString(
RpcResponse.serializer(resultSerializer), responseString)
continuation.resumeWith(
Result.success(decoded)
)
} catch (e: SerializationException){
continuation.resumeWithException(e)
}
}
else -> {
val errorString = errorStream.bufferedReader().use { it.readText() }
continuation.resumeWithException(Exception(errorString))
}
}
}
}
Expand Down

0 comments on commit e19e5a9

Please sign in to comment.