commit 3c85267950af7a1a26ebf5a25dd1c011847ddd65
parent 845dae82a57ca8e088ee0724490811f8e95c0827
Author: Marcello Stanisci <stanisci.m@gmail.com>
Date: Thu, 7 Nov 2019 14:19:55 +0100
Throwing exception on EBICS-specific error as well.
Diffstat:
1 file changed, 13 insertions(+), 13 deletions(-)
diff --git a/nexus/src/main/kotlin/Main.kt b/nexus/src/main/kotlin/Main.kt
@@ -108,6 +108,8 @@ suspend inline fun <reified S, reified T>HttpClient.postToBank(url: String, body
data class NotAnIdError(val statusCode: HttpStatusCode) : Exception("String ID not convertible in number")
data class SubscriberNotFoundError(val statusCode: HttpStatusCode) : Exception("Subscriber not found in database")
data class UnreachableBankError(val statusCode: HttpStatusCode) : Exception("Could not reach the bank")
+data class EbicsError(val codeError: String) : Exception("Bank did not accepted EBICS request, error is: " +
+ "${codeError}")
fun main() {
@@ -147,6 +149,11 @@ fun main() {
call.respondText("Subscriber not found\n", ContentType.Text.Plain, HttpStatusCode.NotFound)
}
+ exception<EbicsError> { cause ->
+ logger.error("Exception while handling '${call.request.uri}'", cause)
+ call.respondText("Bank gave EBICS-error response\n", ContentType.Text.Plain, HttpStatusCode.NotAcceptable)
+ }
+
exception<javax.xml.bind.UnmarshalException> { cause ->
logger.error("Exception while handling '${call.request.uri}'", cause)
call.respondText(
@@ -268,20 +275,13 @@ fun main() {
) ?: throw UnreachableBankError(HttpStatusCode.InternalServerError)
val returnCode = responseJaxb.value.body.returnCode.value
- if (returnCode == "000000") {
- call.respond(
- HttpStatusCode.OK,
- NexusError("Sandbox accepted the key.")
- )
- return@post
- } else {
+ if (returnCode != "000000") throw EbicsError(returnCode)
- call.respond(
- HttpStatusCode.OK,
- NexusError("Sandbox did not accept the key. Error code: ${returnCode}")
- )
- return@post
- }
+ call.respond(
+ HttpStatusCode.OK,
+ NexusError("Sandbox accepted the key!")
+ )
+ return@post
}
}
}