summaryrefslogtreecommitdiff
path: root/nexus/src/main/kotlin/tech/libeufin/nexus/Taler.kt
diff options
context:
space:
mode:
authorMS <ms@taler.net>2023-07-18 14:33:40 +0200
committerMS <ms@taler.net>2023-07-18 14:33:40 +0200
commitfdddd2f9f2f4d1b3daa0a74d3aeb51b51d5c8e02 (patch)
treec3acbcb546d47104c1930a2659b0ec083ce816e9 /nexus/src/main/kotlin/tech/libeufin/nexus/Taler.kt
parent5b56ad9ed803b3a1105e6333716dcfca7593a3f1 (diff)
downloadlibeufin-fdddd2f9f2f4d1b3daa0a74d3aeb51b51d5c8e02.tar.gz
libeufin-fdddd2f9f2f4d1b3daa0a74d3aeb51b51d5c8e02.tar.bz2
libeufin-fdddd2f9f2f4d1b3daa0a74d3aeb51b51d5c8e02.zip
Nexus side of /admin/add-incoming.
Responding to the client the same error code that Sandbox gives, except for 5xx where 'Bad Gateway' is responded to the client.
Diffstat (limited to 'nexus/src/main/kotlin/tech/libeufin/nexus/Taler.kt')
-rw-r--r--nexus/src/main/kotlin/tech/libeufin/nexus/Taler.kt22
1 files changed, 19 insertions, 3 deletions
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Taler.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/Taler.kt
index cebb250d..2aa02121 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/Taler.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/Taler.kt
@@ -27,6 +27,7 @@ import io.ktor.server.application.call
import io.ktor.client.*
import io.ktor.client.plugins.*
import io.ktor.client.request.*
+import io.ktor.client.statement.*
import io.ktor.content.TextContent
import io.ktor.http.*
import io.ktor.server.request.receive
@@ -613,18 +614,29 @@ private suspend fun addIncoming(call: ApplicationCall) {
)
}
val client = HttpClient { followRedirects = true }
- client.post(fromDb.first) {
+ val resp = client.post(fromDb.first) {
setBody(currentBody)
basicAuth("exchange", "x")
contentType(ContentType.Application.Json)
- expectSuccess = true
+ expectSuccess = false
+ }
+ // Sandbox itself failed. Responding Bad Gateway because here is a proxy.
+ if (resp.status.value.toString().startsWith('5')) {
+ logger.error("Sandbox failed with status code: ${resp.status.description}")
+ throw badGateway("Sandbox failed at creating the 'admin/add-incoming' payment")
+ }
+ // Echo back whatever error is left, because that should be the client fault.
+ if (!resp.status.value.toString().startsWith('2')) {
+ logger.error("Client-side error for /admin/add-incoming. Sandbox says: ${resp.bodyAsText()}")
+ call.respond(resp.status, resp.bodyAsText())
}
/**
* At this point, Sandbox booked the payment. Now the "row_id"
* value to put in the response needs to be resorted; that may
* be known by fetching a fresh C52 report, then let Nexus ingest
* the result, and finally _optimistically_ pick the latest entry
- * in the received payments. */
+ * in the received payments. NOTE: if this fails, the global handler
+ * responds 500 as this should _never_ fail. */
fetchBankAccountTransactions(
client,
FetchSpecLatestJson(
@@ -639,6 +651,10 @@ private suspend fun addIncoming(call: ApplicationCall) {
*/
val lastIncomingPayment = transaction {
val allIncomingPayments = TalerIncomingPaymentEntity.all()
+ /**
+ * One payment must appear, since it was created BY this handler.
+ * If not, then respond 500.
+ */
if (allIncomingPayments.empty())
throw internalServerError("Incoming payment(s) not found AFTER /add-incoming")
val lastRecord = allIncomingPayments.last()