commit 78a7d128bef3763877c285cec1bc6457bdb69b8f
parent 478947a7e131a1659a29bc48031f813360b5eab1
Author: MS <ms@taler.net>
Date: Thu, 9 Jul 2020 19:11:49 +0200
align sandbox to nexus style
Diffstat:
4 files changed, 48 insertions(+), 15 deletions(-)
diff --git 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
@@ -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
@@ -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
@@ -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