diff options
author | Antoine A <> | 2024-03-08 18:34:18 +0100 |
---|---|---|
committer | Antoine A <> | 2024-03-08 18:34:18 +0100 |
commit | 16b5d74cad21d533353b0412b78302dcd37304f8 (patch) | |
tree | 042d8f6d806c7b10ffbd84b9574eb7d452568136 | |
parent | 298557c74a4fa8112cb4c8b0be644496d77e74a1 (diff) | |
download | libeufin-16b5d74cad21d533353b0412b78302dcd37304f8.tar.gz libeufin-16b5d74cad21d533353b0412b78302dcd37304f8.tar.bz2 libeufin-16b5d74cad21d533353b0412b78302dcd37304f8.zip |
Better error message during ebics-setup
-rw-r--r-- | common/src/main/kotlin/Cli.kt | 2 | ||||
-rw-r--r-- | nexus/src/main/kotlin/tech/libeufin/nexus/EbicsSetup.kt | 30 | ||||
-rw-r--r-- | nexus/src/main/kotlin/tech/libeufin/nexus/ebics/EbicsCommon.kt | 2 |
3 files changed, 21 insertions, 13 deletions
diff --git a/common/src/main/kotlin/Cli.kt b/common/src/main/kotlin/Cli.kt index 52c3ada3..fcf17688 100644 --- a/common/src/main/kotlin/Cli.kt +++ b/common/src/main/kotlin/Cli.kt @@ -46,7 +46,7 @@ fun Throwable.fmtLog(logger: Logger) { cause = cause.cause } logger.error(msg.toString()) - logger.debug("{}", this) + logger.trace("", this) } fun cliCmd(logger: Logger, level: Level, lambda: suspend () -> Unit) { diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsSetup.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsSetup.kt index 916014e7..230b2cc9 100644 --- a/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsSetup.kt +++ b/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsSetup.kt @@ -118,7 +118,19 @@ suspend fun doKeysRequestAndUpdateState( } val xml = client.postToBank(cfg.hostBaseUrl, req) val resp = Ebics3KeyMng.parseResponse(xml, privs.encryption_private_key) - // TODO better error messages for expected errros + + when (orderType) { + KeysOrderType.INI, KeysOrderType.HIA -> { + if (resp.technicalCode == EbicsReturnCode.EBICS_INVALID_USER_OR_USER_STATE) { + throw Exception("$orderType status code ${resp.technicalCode}: either your IDs are incorrect, or you already have keys registered with this bank") + } + } + KeysOrderType.HPB -> { + if (resp.technicalCode == EbicsReturnCode.EBICS_AUTHENTICATION_FAILED) { + throw Exception("$orderType status code ${resp.technicalCode}: could not download bank keys, send client keys (and/or related PDF document with --generate-registration-pdf) to the bank") + } + } + } val orderData = resp.okOrFail("${orderType.name}") when (orderType) { @@ -220,16 +232,12 @@ class EbicsSetup: CliktCommand("Set up the EBICS subscriber") { // Checking if the bank keys exist on disk. var bankKeys = loadBankKeys(cfg.bankPublicKeysFilename) if (bankKeys == null) { - try { - doKeysRequestAndUpdateState( - cfg, - clientKeys, - httpClient, - KeysOrderType.HPB - ) - } catch (e: Exception) { - throw Exception("Could not download bank keys. Send client keys (and/or related PDF document with --generate-registration-pdf) to the bank", e) - } + doKeysRequestAndUpdateState( + cfg, + clientKeys, + httpClient, + KeysOrderType.HPB + ) logger.info("Bank keys stored at ${cfg.bankPublicKeysFilename}") bankKeys = loadBankKeys(cfg.bankPublicKeysFilename)!! } diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/EbicsCommon.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/EbicsCommon.kt index 63cac5cf..8fd7e07b 100644 --- a/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/EbicsCommon.kt +++ b/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/EbicsCommon.kt @@ -443,7 +443,7 @@ enum class EbicsReturnCode(val code: String) { EBICS_NO_DOWNLOAD_DATA_AVAILABLE("090005"), EBICS_INVALID_USER_OR_USER_STATE("091002"), EBICS_USER_UNKNOWN("091003"), - EBICS_EBICS_INVALID_USER_STATE("091004"), + EBICS_INVALID_USER_STATE("091004"), EBICS_INVALID_ORDER_IDENTIFIER("091005"), EBICS_UNSUPPORTED_ORDER_TYPE("091006"), EBICS_INVALID_XML("091010"), |