gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libeufin] 01/04: Polishing


From: gnunet
Subject: [libeufin] 01/04: Polishing
Date: Tue, 31 Jan 2023 17:22:57 +0100

This is an automated email from the git hooks/post-receive script.

ms pushed a commit to branch master
in repository libeufin.

commit 0b3de446d10454cbb58953d8258f2cb5fe618258
Author: MS <ms@taler.net>
AuthorDate: Tue Jan 31 16:51:56 2023 +0100

    Polishing
---
 .../tech/libeufin/nexus/server/NexusServer.kt      | 49 ++++++++++++----------
 .../src/main/kotlin/tech/libeufin/sandbox/Main.kt  |  2 +-
 2 files changed, 29 insertions(+), 22 deletions(-)

diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt 
b/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt
index b8c33065..b600fbcd 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt
@@ -46,6 +46,7 @@ import io.ktor.server.routing.*
 import io.ktor.util.*
 import org.jetbrains.exposed.exceptions.ExposedSQLException
 import org.jetbrains.exposed.sql.and
+import org.jetbrains.exposed.sql.transactions.TransactionManager
 import org.jetbrains.exposed.sql.transactions.transaction
 import org.slf4j.event.Level
 import tech.libeufin.nexus.*
@@ -211,13 +212,24 @@ val nexusApp: Application.() -> Unit = {
                 )
             )
         }
-        exception<BadRequestException> { call, cause ->
-            logger.error("Exception while handling '${call.request.uri}', 
${cause.message}")
+        exception<BadRequestException> { call, wrapper ->
+            var rootCause = wrapper.cause
+            while (rootCause?.cause != null) rootCause = rootCause.cause
+            val errorMessage: String? = rootCause?.message ?: wrapper.message
+            if (errorMessage == null) {
+                logger.error("The bank didn't detect the cause of a bad 
request, fail.")
+                logger.error(wrapper.stackTraceToString())
+                throw NexusError(
+                    HttpStatusCode.InternalServerError,
+                    "Did not find bad request details."
+                )
+            }
+            logger.error(errorMessage)
             call.respond(
                 HttpStatusCode.BadRequest,
                 ErrorResponse(
                     code = 
TalerErrorCode.TALER_EC_LIBEUFIN_NEXUS_GENERIC_ERROR.code,
-                    detail = cause.message ?: "Bad request but did not find 
exact cause.",
+                    detail = errorMessage,
                     hint = "Malformed request or unacceptable values"
                 )
             )
@@ -953,32 +965,27 @@ val nexusApp: Application.() -> Unit = {
                     HttpStatusCode.NotImplemented,
                     "Facade type '${body.type}' is not implemented"
                 )
-            val newFacade = try {
+            try {
                 transaction {
                     val user = authenticateRequest(call.request)
-                    FacadeEntity.new {
+                    val newFacade = FacadeEntity.new {
                         facadeName = body.name
                         type = body.type
                         creator = user
                     }
+                    FacadeStateEntity.new {
+                        bankAccount = body.config.bankAccount
+                        bankConnection = body.config.bankConnection
+                        reserveTransferLevel = body.config.reserveTransferLevel
+                        facade = newFacade
+                        currency = body.config.currency
+                    }
                 }
-            } catch (e: ExposedSQLException) {
-                logger.error("Could not persist facade name/type/creator: $e")
-                throw NexusError(
-                    HttpStatusCode.BadRequest,
-                    "Server could not persist data, possibly due to 
unavailable facade name"
-                )
-            }
-            transaction {
-                FacadeStateEntity.new {
-                    bankAccount = body.config.bankAccount
-                    bankConnection = body.config.bankConnection
-                    reserveTransferLevel = body.config.reserveTransferLevel
-                    facade = newFacade
-                    currency = body.config.currency
-                }
+            } catch (e: Exception) {
+                logger.error(e.stackTraceToString())
+                throw internalServerError("Could not create facade")
             }
-            call.respondText("Facade created")
+            call.respond(HttpStatusCode.OK)
             return@post
         }
 
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt 
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
index d0ab1a8b..072a5acc 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
@@ -571,7 +571,7 @@ val sandboxApp: Application.() -> Unit = {
                 HttpStatusCode.BadRequest,
                 SandboxErrorJson(
                     error = SandboxErrorDetailJson(
-                        type = "util-error",
+                        type = "sandbox-error",
                         description = errorMessage
                     )
                 )

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]