changed the errorMsg to return the whole response body in case of any unknown json message from server in TransactionExecutor.kt

This commit is contained in:
2024-09-25 14:33:17 +05:30
parent 66dde20601
commit 8046dd0e62
7 changed files with 54 additions and 39 deletions

View File

@@ -19,7 +19,7 @@ import javax.net.ssl.HostnameVerifier
class TransactionExecutor() {
private val protocol = "https"
private val host = "180.179.119.227"
private val host = "180.179.110.185"
private val port = "443"
private val rootRoute = "IPKS_Queue_Generation"
private val remoteUrl = "$protocol://$host:$port/$rootRoute"
@@ -28,14 +28,15 @@ class TransactionExecutor() {
val transferTransaction = transactionPair.first
val neftTransaction = transactionPair.second
val transferResponse = execute(Json.encodeToString(transferTransaction))
val neftResponse = execute(Json.encodeToString(neftTransaction))
return Pair(transferResponse, neftResponse)
}
private fun execute(postBody: String): TransactionResponse {
val transferRoute = "Ipks"
// println(postBody)
val transferRoute = "IpksApi"
val transferURL = "$remoteUrl/$transferRoute"
val jsonMediaType = "application/json; charset=utf-8".toMediaType()
@@ -52,9 +53,9 @@ class TransactionExecutor() {
val responseBody = httpClient.newCall(request).execute().use { response ->
if (!response.isSuccessful) {
throw IOException("Unexpected code $response")
throw IOException("Unexpected response: ${response.body}")
}
response.body!!.string()
response.body?.string() ?: throw IOException("no response body")
}
val responseObj = JSONObject(responseBody)
@@ -66,7 +67,7 @@ class TransactionExecutor() {
val queueNo = try { responseObj.getJSONObject("response").getString("QueueId") } catch(_: JSONException) { "" }
return TransactionSuccessResponse(status, message, queueNo, error)
} else {
val errorMsg = try { responseObj.getJSONObject("response").getString("errorMsg") } catch(_: JSONException) { "no error message provided" }
val errorMsg = try { responseObj.getJSONObject("response").getString("errorMsg") } catch(_: JSONException) { responseBody }
return TransactionFailureResponse(status, message, errorMsg, error)
}
return response