[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libeufin] branch master updated: Renaming the error response type.
From: |
gnunet |
Subject: |
[libeufin] branch master updated: Renaming the error response type. |
Date: |
Thu, 09 Jul 2020 17:37:36 +0200 |
This is an automated email from the git hooks/post-receive script.
ms pushed a commit to branch master
in repository libeufin.
The following commit(s) were added to refs/heads/master by this push:
new 7ea6b65 Renaming the error response type.
7ea6b65 is described below
commit 7ea6b65786704ec04f6f42d669680c0b1e30de3c
Author: MS <ms@taler.net>
AuthorDate: Thu Jul 9 17:35:25 2020 +0200
Renaming the error response type.
Removing the "ebics" part from name, so as to reuse
it in any error situation.
---
.../tech/libeufin/nexus/ebics/EbicsClient.kt | 2 +-
.../kotlin/tech/libeufin/nexus/ebics/EbicsNexus.kt | 12 ++----
.../main/kotlin/tech/libeufin/nexus/server/JSON.kt | 9 ++---
.../tech/libeufin/nexus/server/NexusServer.kt | 47 +++++++++++++---------
util/src/main/kotlin/Ebics.kt | 5 ++-
5 files changed, 40 insertions(+), 35 deletions(-)
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/EbicsClient.kt
b/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/EbicsClient.kt
index b059b2d..426c2c0 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/EbicsClient.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/EbicsClient.kt
@@ -85,7 +85,7 @@ suspend fun doEbicsDownloadTransaction(
// Success, nothing to do!
}
else -> {
- throw NexusError(
+ throw EbicsProtocolError(
HttpStatusCode.InternalServerError,
"unexpected return code ${initResponse.technicalReturnCode}"
)
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/EbicsNexus.kt
b/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/EbicsNexus.kt
index 9affd67..21d9733 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/EbicsNexus.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/EbicsNexus.kt
@@ -35,16 +35,12 @@ import io.ktor.application.call
import io.ktor.client.HttpClient
import io.ktor.http.ContentType
import io.ktor.http.HttpStatusCode
-import io.ktor.request.receive
import io.ktor.request.receiveOrNull
import io.ktor.response.respond
import io.ktor.response.respondText
import io.ktor.routing.Route
-import io.ktor.routing.get
import io.ktor.routing.post
-import org.jetbrains.exposed.sql.and
import org.jetbrains.exposed.sql.insert
-import org.jetbrains.exposed.sql.not
import org.jetbrains.exposed.sql.statements.api.ExposedBlob
import org.jetbrains.exposed.sql.transactions.transaction
import tech.libeufin.nexus.*
@@ -523,10 +519,10 @@ fun Route.ebicsBankConnectionRoutes(client: HttpClient) {
is EbicsDownloadBankErrorResult -> {
call.respond(
HttpStatusCode.BadGateway,
- EbicsErrorJson(
- EbicsErrorDetailJson(
- "bankError",
- response.returnCode.errorCode
+ NexusErrorJson(
+ error = NexusErrorDetailJson(
+ type = "bank-error",
+ description = response.returnCode.errorCode
)
)
)
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/server/JSON.kt
b/nexus/src/main/kotlin/tech/libeufin/nexus/server/JSON.kt
index 01d6996..cbba260 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/server/JSON.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/server/JSON.kt
@@ -104,13 +104,12 @@ class EbicsStandardOrderParamsDateJson(
}
}
-data class EbicsErrorDetailJson(
+data class NexusErrorDetailJson(
val type: String,
- val ebicsReturnCode: String
+ val description: String
)
-
-data class EbicsErrorJson(
- val error: EbicsErrorDetailJson
+data class NexusErrorJson(
+ val error: NexusErrorDetailJson
)
data class BankConnectionInfo(
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 29b011a..acd5297 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt
@@ -82,7 +82,7 @@ fun ensureLong(param: String?): Long {
}
fun <T> expectNonNull(param: T?): T {
- return param ?: throw EbicsProtocolError(
+ return param ?: throw NexusError(
HttpStatusCode.BadRequest,
"Non-null value expected."
)
@@ -153,7 +153,7 @@ fun ApplicationRequest.hasBody(): Boolean {
fun ApplicationCall.expectUrlParameter(name: String): String {
return this.request.queryParameters[name]
- ?: throw EbicsProtocolError(HttpStatusCode.BadRequest, "Parameter
'$name' not provided in URI")
+ ?: throw NexusError(HttpStatusCode.BadRequest, "Parameter '$name' not
provided in URI")
}
suspend inline fun <reified T : Any> ApplicationCall.receiveJson(): T {
@@ -193,12 +193,13 @@ fun requireBankConnectionInternal(connId: String):
NexusBankConnectionEntity {
fun requireBankConnection(call: ApplicationCall, parameterKey: String):
NexusBankConnectionEntity {
val name = call.parameters[parameterKey]
if (name == null) {
- throw NexusError(HttpStatusCode.InternalServerError, "no parameter for
bank connection")
+ throw NexusError(HttpStatusCode.NotFound,
+ "Parameter '${parameterKey}' wasn't found in URI"
+ )
}
return requireBankConnectionInternal(name)
}
-
fun serverMain(dbName: String, host: String) {
dbCreateTables(dbName)
val client = HttpClient {
@@ -219,35 +220,43 @@ fun serverMain(dbName: String, host: String) {
registerModule(KotlinModule(nullisSameAsDefault = true))
}
}
-
install(StatusPages) {
exception<NexusError> { cause ->
logger.error("Exception while handling '${call.request.uri}'",
cause)
- call.respondText(
- cause.reason,
- ContentType.Text.Plain,
- cause.statusCode
+ call.respond(
+ status = cause.statusCode,
+ message = NexusErrorJson(
+ error = NexusErrorDetailJson(
+ description = cause.reason,
+ type = "nexus-error"
+ )
+ )
)
}
exception<EbicsProtocolError> { cause ->
logger.error("Exception while handling '${call.request.uri}'",
cause)
- call.respondText(
- cause.reason,
- ContentType.Text.Plain,
- cause.statusCode
+ call.respond(
+ NexusErrorJson(
+ error = NexusErrorDetailJson(
+ type = "ebics-protocol-error",
+ description = cause.reason
+ )
+ )
)
}
exception<Exception> { cause ->
logger.error("Uncaught exception while handling
'${call.request.uri}'", cause)
logger.error(cause.toString())
- call.respondText(
- "Internal server error",
- ContentType.Text.Plain,
- HttpStatusCode.InternalServerError
+ call.respond(
+ NexusErrorJson(
+ error = NexusErrorDetailJson(
+ type = "nexus-error",
+ description = "Internal server error"
+ )
+ )
)
}
}
-
intercept(ApplicationCallPipeline.Fallback) {
if (this.call.response.status() == null) {
call.respondText("Not found (no route matched).\n",
ContentType.Text.Plain, HttpStatusCode.NotFound)
@@ -267,9 +276,7 @@ fun serverMain(dbName: String, host: String) {
proceed()
return@intercept
}
-
startOperationScheduler(client)
-
routing {
// Shows information about the requesting user.
get("/user") {
diff --git a/util/src/main/kotlin/Ebics.kt b/util/src/main/kotlin/Ebics.kt
index 1c7e167..b867d79 100644
--- a/util/src/main/kotlin/Ebics.kt
+++ b/util/src/main/kotlin/Ebics.kt
@@ -39,7 +39,10 @@ import java.util.zip.DeflaterInputStream
import javax.xml.datatype.DatatypeFactory
import javax.xml.datatype.XMLGregorianCalendar
-data class EbicsProtocolError(val statusCode: HttpStatusCode, val reason:
String) : Exception(reason)
+data class EbicsProtocolError(
+ val httpStatusCode: HttpStatusCode,
+ val reason: String
+) : Exception(reason)
data class EbicsDateRange(val start: ZonedDateTime, val end: ZonedDateTime)
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [libeufin] branch master updated: Renaming the error response type.,
gnunet <=