summaryrefslogtreecommitdiff
path: root/wallet/src/main/java/net/taler/wallet/backend
diff options
context:
space:
mode:
authorTorsten Grote <t@grobox.de>2020-09-01 11:12:31 -0300
committerTorsten Grote <t@grobox.de>2020-09-01 11:13:17 -0300
commitc928b458fce0c72c75852ab338a6e4e85a278ed4 (patch)
tree02f70b9be6ca1cc5cb30ad41631bac92d9f49ed0 /wallet/src/main/java/net/taler/wallet/backend
parentc59243c9bdabf07137ad0f070b6ecbde57e66466 (diff)
downloadtaler-android-c928b458fce0c72c75852ab338a6e4e85a278ed4.tar.gz
taler-android-c928b458fce0c72c75852ab338a6e4e85a278ed4.tar.bz2
taler-android-c928b458fce0c72c75852ab338a6e4e85a278ed4.zip
[wallet] support the new TalerErrorInfo error format
Yet another last-minute breaking protocol change.
Diffstat (limited to 'wallet/src/main/java/net/taler/wallet/backend')
-rw-r--r--wallet/src/main/java/net/taler/wallet/backend/WalletBackendApi.kt18
-rw-r--r--wallet/src/main/java/net/taler/wallet/backend/WalletBackendService.kt12
-rw-r--r--wallet/src/main/java/net/taler/wallet/backend/WalletResponse.kt19
3 files changed, 27 insertions, 22 deletions
diff --git a/wallet/src/main/java/net/taler/wallet/backend/WalletBackendApi.kt b/wallet/src/main/java/net/taler/wallet/backend/WalletBackendApi.kt
index a72df9c..a2b48b6 100644
--- a/wallet/src/main/java/net/taler/wallet/backend/WalletBackendApi.kt
+++ b/wallet/src/main/java/net/taler/wallet/backend/WalletBackendApi.kt
@@ -157,20 +157,20 @@ class WalletBackendApi(
}
}
sendRequest(operation, args?.invoke(JSONObject())) { isError, message ->
- val response = if (isError) {
- val error =
- json.decodeFromString(WalletErrorInfo.serializer(), message.toString())
- WalletResponse.Error(error)
- } else {
- try {
+ val response = try {
+ if (isError) {
+ val error =
+ json.decodeFromString(TalerErrorInfo.serializer(), message.toString())
+ WalletResponse.Error(error)
+ } else {
val t: T = serializer?.let {
json.decodeFromString(serializer, message.toString())
} ?: Unit as T
WalletResponse.Success(t)
- } catch (e: Exception) {
- val info = WalletErrorInfo(0, "", e.toString(), null)
- WalletResponse.Error(info)
}
+ } catch (e: Exception) {
+ val info = TalerErrorInfo(0, "", e.toString(), null)
+ WalletResponse.Error(info)
}
cont.resume(response)
}
diff --git a/wallet/src/main/java/net/taler/wallet/backend/WalletBackendService.kt b/wallet/src/main/java/net/taler/wallet/backend/WalletBackendService.kt
index 993114c..c8a2bad 100644
--- a/wallet/src/main/java/net/taler/wallet/backend/WalletBackendService.kt
+++ b/wallet/src/main/java/net/taler/wallet/backend/WalletBackendService.kt
@@ -184,13 +184,16 @@ class WalletBackendService : Service() {
private fun handleAkonoMessage(messageStr: String) {
val message = JSONObject(messageStr)
- Log.v(TAG, "got back message: ${message.toString(2)}")
when (val type = message.getString("type")) {
"notification" -> {
- sendNotify(message.getString("payload"))
+ val payload = message.getJSONObject("payload")
+ if (payload.optString("type") != "waiting-for-retry") {
+ Log.v(TAG, "got back notification: ${message.toString(2)}")
+ }
+ sendNotify(payload.toString())
}
"tunnelHttp" -> {
- Log.v(TAG, "got http tunnel request!")
+ Log.v(TAG, "got http tunnel request! ${message.toString(2)}")
Intent().also { intent ->
intent.action = HostCardEmulatorService.HTTP_TUNNEL_REQUEST
intent.putExtra("tunnelMessage", messageStr)
@@ -204,15 +207,18 @@ class WalletBackendService : Service() {
sendNotify(message.toString(2))
}
"reset" -> {
+ Log.v(TAG, "got back message: ${message.toString(2)}")
exitProcess(1)
}
else -> {
+ Log.v(TAG, "got back response: ${message.toString(2)}")
val payload = message.getJSONObject("result").toString(2)
handleResponse(false, message, payload)
}
}
}
"error" -> {
+ Log.v(TAG, "got back error: ${message.toString(2)}")
val payload = message.getJSONObject("error").toString(2)
handleResponse(true, message, payload)
}
diff --git a/wallet/src/main/java/net/taler/wallet/backend/WalletResponse.kt b/wallet/src/main/java/net/taler/wallet/backend/WalletResponse.kt
index 5826997..2476607 100644
--- a/wallet/src/main/java/net/taler/wallet/backend/WalletResponse.kt
+++ b/wallet/src/main/java/net/taler/wallet/backend/WalletResponse.kt
@@ -38,7 +38,7 @@ sealed class WalletResponse<T> {
@Serializable
@SerialName("error")
data class Error<T>(
- val error: WalletErrorInfo
+ val error: TalerErrorInfo
) : WalletResponse<T>()
fun onSuccess(block: (result: T) -> Unit): WalletResponse<T> {
@@ -46,35 +46,34 @@ sealed class WalletResponse<T> {
return this
}
- fun onError(block: (result: WalletErrorInfo) -> Unit): WalletResponse<T> {
+ fun onError(block: (result: TalerErrorInfo) -> Unit): WalletResponse<T> {
if (this is Error) block(this.error)
return this
}
}
@Serializable
-data class WalletErrorInfo(
+data class TalerErrorInfo(
// Numeric error code defined defined in the
// GANA gnu-taler-error-codes registry.
- val talerErrorCode: Int,
+ val code: Int,
// English description of the error code.
- val talerErrorHint: String,
+ val hint: String?,
// English diagnostic message that can give details
// for the instance of the error.
- val message: String,
+ val message: String?,
- // Error details, type depends on talerErrorCode
+ // Error details
@Serializable(JSONObjectDeserializer::class)
val details: JSONObject?
) {
val userFacingMsg: String
get() {
return StringBuilder().apply {
- append(talerErrorCode)
- append(" ")
- append(message)
+ append(code)
+ message?.let { append(" ").append(it) }
details?.let { details ->
append("\n\n")
details.optJSONObject("errorResponse")?.let { errorResponse ->