[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libeufin] 01/01: align sandbox to nexus style
From: |
gnunet |
Subject: |
[libeufin] 01/01: align sandbox to nexus style |
Date: |
Thu, 09 Jul 2020 20:22:02 +0200 |
This is an automated email from the git hooks/post-receive script.
ms pushed a commit to branch master
in repository libeufin.
commit 78a7d128bef3763877c285cec1bc6457bdb69b8f
Author: MS <ms@taler.net>
AuthorDate: Thu Jul 9 19:11:49 2020 +0200
align sandbox to nexus style
---
integration-tests/test-bankConnection.py | 1 -
.../tech/libeufin/sandbox/EbicsProtocolBackend.kt | 12 +++---
.../src/main/kotlin/tech/libeufin/sandbox/Main.kt | 47 +++++++++++++++++-----
util/src/main/kotlin/JSON.kt | 3 ++
4 files changed, 48 insertions(+), 15 deletions(-)
diff --git a/integration-tests/test-bankConnection.py
b/integration-tests/test-bankConnection.py
index be15195..c1bd264 100755
--- a/integration-tests/test-bankConnection.py
+++ b/integration-tests/test-bankConnection.py
@@ -143,7 +143,6 @@ connectionsList = resp.json().get("bankConnections")
assert(connectionsList != None)
for el in connectionsList:
- print(el)
if el.get("name") == "my-ebics":
print("fail: account not deleted!")
exit(1)
diff --git
a/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt
index f7490e5..088b8b5 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt
@@ -50,7 +50,6 @@ import java.util.zip.InflaterInputStream
open class EbicsRequestError(errorText: String, errorCode: String) :
Exception("EBICS request error: $errorText ($errorCode)")
-
class EbicsInvalidRequestError : EbicsRequestError(
"[EBICS_INVALID_REQUEST] Invalid request",
"060102"
@@ -296,10 +295,13 @@ fun buildCamtString(type: Int, subscriberIban: String,
history: MutableList<RawP
text(dashedDate)
} // date of assets' actual (un)availability
element("AcctSvcrRef") {
- val uid = if (it.uid != null)
it.uid.toString() else throw SandboxError(
- HttpStatusCode.InternalServerError,
- "Payment ${it.subject} doesn't have a
UID!"
- )
+ val uid = if (it.uid != null)
it.uid.toString() else {
+ LOGGER.error("")
+ throw EbicsRequestError(
+ errorCode = "091116",
+ errorText =
"EBICS_PROCESSING_ERROR"
+ )
+ }
text(uid)
}
element("BkTxCd") {
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
index 7d33dc0..c1fe3d4 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
@@ -70,10 +70,9 @@ class UnacceptableFractional(badNumber: BigDecimal) :
Exception(
)
lateinit var LOGGER: Logger
-data class SandboxError(
- val statusCode: HttpStatusCode,
- val reason: String
-) : java.lang.Exception()
+data class SandboxError(val statusCode: HttpStatusCode, val reason: String) :
Exception()
+data class SandboxErrorJson(val error: SandboxErrorDetailJson)
+data class SandboxErrorDetailJson(val type: String, val description: String)
class SandboxCommand : CliktCommand() {
override fun run() = Unit
@@ -158,16 +157,46 @@ fun serverMain(dbName: String) {
}
}
install(StatusPages) {
- exception<Throwable> { cause ->
+ exception<ArithmeticException> { cause ->
LOGGER.error("Exception while handling '${call.request.uri}'",
cause)
- call.respondText("Internal server error.",
ContentType.Text.Plain, HttpStatusCode.InternalServerError)
+ call.respondText(
+ "Invalid arithmetic attempted.",
+ ContentType.Text.Plain,
+ // here is always the bank's fault, as it should always
check
+ // the operands.
+ HttpStatusCode.InternalServerError
+ )
}
- exception<ArithmeticException> { cause ->
+
+ exception<EbicsRequestError> { cause ->
+ LOGGER.info("Client EBICS request was invalid")
+ // fixme: this error should respond with XML!
+ call.respondText(
+ cause.localizedMessage,
+ ContentType.Text.Any,
+ HttpStatusCode.OK
+ )
+ }
+
+ // todo: check that this error is never thrown upon EBICS errors.
+ exception<SandboxError> { cause ->
+ LOGGER.error("Exception while handling '${call.request.uri}'",
cause)
+ call.respond(
+ cause.statusCode,
+ SandboxErrorJson(
+ error = SandboxErrorDetailJson(
+ type = "sandbox-error",
+ description = cause.reason
+ )
+ )
+ )
+ }
+
+ exception<Throwable> { cause ->
LOGGER.error("Exception while handling '${call.request.uri}'",
cause)
- call.respondText("Invalid arithmetic attempted.",
ContentType.Text.Plain, HttpStatusCode.InternalServerError)
+ call.respondText("Internal server error.",
ContentType.Text.Plain, HttpStatusCode.InternalServerError)
}
}
- // TODO: add another intercept call that adds schema validation before
the response is sent
intercept(ApplicationCallPipeline.Fallback) {
if (this.call.response.status() == null) {
call.respondText("Not found (no route matched).\n",
ContentType.Text.Plain, HttpStatusCode.NotFound)
diff --git a/util/src/main/kotlin/JSON.kt b/util/src/main/kotlin/JSON.kt
index 288df46..0874f67 100644
--- a/util/src/main/kotlin/JSON.kt
+++ b/util/src/main/kotlin/JSON.kt
@@ -35,5 +35,8 @@ data class RawPayment(
val currency: String,
val subject: String,
val date: String? = null,
+ // this (uid) field is null when RawPayment is a _requested_ payment
+ // over the admin API, and it's not null when RawPayment represent
+ // a database row of a settled payment.
val uid: Int? = null
)
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.