summaryrefslogtreecommitdiff
path: root/merchant-lib/src/main/java/net/taler/merchantlib/Response.kt
diff options
context:
space:
mode:
Diffstat (limited to 'merchant-lib/src/main/java/net/taler/merchantlib/Response.kt')
-rw-r--r--merchant-lib/src/main/java/net/taler/merchantlib/Response.kt16
1 files changed, 7 insertions, 9 deletions
diff --git a/merchant-lib/src/main/java/net/taler/merchantlib/Response.kt b/merchant-lib/src/main/java/net/taler/merchantlib/Response.kt
index 6fd0e37..55de077 100644
--- a/merchant-lib/src/main/java/net/taler/merchantlib/Response.kt
+++ b/merchant-lib/src/main/java/net/taler/merchantlib/Response.kt
@@ -16,10 +16,8 @@
package net.taler.merchantlib
-import io.ktor.client.call.receive
-import io.ktor.client.features.ClientRequestException
-import io.ktor.client.features.ResponseException
-import io.ktor.client.features.ServerResponseException
+import io.ktor.client.call.body
+import io.ktor.client.plugins.ResponseException
import kotlinx.serialization.Serializable
class Response<out T> private constructor(
@@ -64,16 +62,15 @@ class Response<out T> private constructor(
}
private suspend fun getFailureString(failure: Failure): String = when (failure.exception) {
- is ClientRequestException -> getExceptionString(failure.exception)
- is ServerResponseException -> getExceptionString(failure.exception)
+ is ResponseException -> getExceptionString(failure.exception)
else -> failure.exception.toString()
}
private suspend fun getExceptionString(e: ResponseException): String {
val response = e.response
return try {
- val error: Error = response.receive()
- "Error ${error.code}: ${error.hint}"
+ val error: Error = response.body()
+ "Error ${error.code} (${response.status.value}): ${error.hint} ${error.detail}"
} catch (ex: Exception) {
"Status code: ${response.status.value}"
}
@@ -84,6 +81,7 @@ class Response<out T> private constructor(
@Serializable
private class Error(
val code: Int?,
- val hint: String?
+ val hint: String?,
+ val detail: String? = null,
)
}