libeufin

Integration and sandbox testing for FinTech APIs and data formats
Log | Files | Refs | Submodules | README | LICENSE

commit 42f6a845dd0769deae0fb9bb43f505e369ef9fcd
parent baf3f567a3cd5551669ff29d28ef72520cea5966
Author: MS <ms@taler.net>
Date:   Tue,  7 Sep 2021 08:38:26 +0000

Wrap ebicsweb() in a try-catch block.

Diffstat:
Msandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt | 5++---
Msandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt | 23++++++++++++++++++++++-
2 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt @@ -109,10 +109,9 @@ private class EbicsUnsupportedOrderType : EbicsRequestError( /** * Used here also for "Internal server error". For example, when the - * sandbox itself generates a invalid XML response. Strictly, this error - * should only be used for _business_ related problems. + * sandbox itself generates a invalid XML response. */ -private class EbicsProcessingError(detail: String) : EbicsRequestError( +class EbicsProcessingError(detail: String) : EbicsRequestError( "[EBICS_PROCESSING_ERROR] $detail", "091116" ) diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt @@ -908,7 +908,28 @@ fun serverMain(dbName: String, port: Int) { * Serves all the Ebics requests. */ post("/ebicsweb") { - call.ebicsweb() + try { + call.ebicsweb() + } + /** + * Those errors were all detected by the bank's logic. + */ + catch (e: SandboxError) { + // Should translate to EBICS error code. + when(e.errorCode) { + LibeufinErrorCode.LIBEUFIN_EC_INVALID_STATE -> throw EbicsProcessingError("Invalid bank state.") + LibeufinErrorCode.LIBEUFIN_EC_INCONSISTENT_STATE -> throw EbicsProcessingError("Inconsistent bank state.") + else -> throw EbicsProcessingError("Unknown LibEuFin error code: ${e.errorCode}.") + } + + } + /** + * An error occurred, but it wasn't explicitly thrown by the bank. + */ + catch (e: Exception) { + throw EbicsProcessingError("Unmanaged error: $e") + } + } } }