gnunet-svn
[Top][All Lists]
Advanced

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

[libeufin] 02/02: Throwing exception on EBICS-specific error as well.


From: gnunet
Subject: [libeufin] 02/02: Throwing exception on EBICS-specific error as well.
Date: Thu, 07 Nov 2019 16:51:51 +0100

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

marcello pushed a commit to branch master
in repository libeufin.

commit 3c85267950af7a1a26ebf5a25dd1c011847ddd65
Author: Marcello Stanisci <address@hidden>
AuthorDate: Thu Nov 7 14:19:55 2019 +0100

    Throwing exception on EBICS-specific error as well.
---
 nexus/src/main/kotlin/Main.kt | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/nexus/src/main/kotlin/Main.kt b/nexus/src/main/kotlin/Main.kt
index 50b1ad9..c4cfba4 100644
--- 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
             }
         }
     }

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

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