From ed784f182713d14b13783dc5f21d6c22d72fde8a Mon Sep 17 00:00:00 2001 From: dankito Date: Mon, 1 Nov 2021 16:46:34 +0100 Subject: [PATCH] Renamed errorMessage to internalError, errorsToShowToUser to errorMessagesFromBank, added didBankReturnError and created a method to determine which error message to show to user --- .../net/dankito/banking/fints/FinTsClient.kt | 3 +-- .../dankito/banking/fints/FinTsJobExecutor.kt | 12 +++++------ .../dankito/banking/fints/RequestExecutor.kt | 6 +++--- .../banking/fints/response/BankResponse.kt | 11 +++++----- .../banking/fints/response/ResponseParser.kt | 2 +- .../response/client/FinTsClientResponse.kt | 21 +++++++++++++------ .../client/GetTransactionsResponse.kt | 4 ++-- .../client/GetUserTanMethodsResponse.kt | 2 +- .../fints/response/ResponseParserTest.kt | 2 +- .../ui/model/responses/AddAccountResponse.kt | 3 ++- .../model/responses/BankingClientResponse.kt | 1 + .../responses/GetTransactionsResponse.kt | 3 ++- .../banking/mapper/fints4kModelMapper.kt | 13 +++--------- 13 files changed, 44 insertions(+), 39 deletions(-) diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsClient.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsClient.kt index 2d713a6f..443a86fd 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsClient.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsClient.kt @@ -4,7 +4,6 @@ import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch import net.dankito.banking.fints.callback.FinTsClientCallback import net.dankito.banking.fints.messages.datenelemente.implementierte.tan.* -import net.dankito.banking.fints.messages.segmente.id.CustomerSegmentId import net.dankito.banking.fints.model.* import net.dankito.banking.fints.response.BankResponse import net.dankito.banking.fints.response.client.* @@ -122,7 +121,7 @@ open class FinTsClient( tryGetTransactionsOfLast90DaysWithoutTan(bank, account) { response -> retrievedAccountData.put(account, response.retrievedData.first()) - if (response.errorMessage != null) { + if (response.internalError != null) { //getAccountsResponse.errorMessage = response.errorMessage } diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsJobExecutor.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsJobExecutor.kt index 9791220b..59b056ad 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsJobExecutor.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsJobExecutor.kt @@ -157,7 +157,7 @@ open class FinTsJobExecutor( if (anonymousBankInfoResponse.successful == false) { callback(anonymousBankInfoResponse) } else if (bank.tanMethodSupportedByBank.isEmpty()) { // should only be a theoretical error - callback(BankResponse(true, errorMessage = "Die TAN Verfahren der Bank konnten nicht ermittelt werden")) // TODO: translate + callback(BankResponse(true, internalError = "Die TAN Verfahren der Bank konnten nicht ermittelt werden")) // TODO: translate } else { bank.tanMethodsAvailableForUser = bank.tanMethodSupportedByBank @@ -263,7 +263,7 @@ open class FinTsJobExecutor( val fromDate = parameter.fromDate ?: parameter.account.countDaysForWhichTransactionsAreKept?.let { Date.today.addDays(it * -1) } ?: bookedTransactions.map { it.valueDate }.sortedBy { it.millisSinceEpoch }.firstOrNull() - val retrievedData = RetrievedAccountData(parameter.account, successful, balance, bookedTransactions, unbookedTransactions, fromDate, parameter.toDate ?: Date.today, response.errorMessage) + val retrievedData = RetrievedAccountData(parameter.account, successful, balance, bookedTransactions, unbookedTransactions, fromDate, parameter.toDate ?: Date.today, response.internalError) callback( GetTransactionsResponse(response, listOf(retrievedData), @@ -344,7 +344,7 @@ open class FinTsJobExecutor( this.callback.enterTanGeneratorAtc(bank, newActiveTanMedium) { enteredAtc -> if (enteredAtc.hasAtcBeenEntered == false) { val message = "Bank requires to enter ATC and TAN in order to change TAN medium." // TODO: translate - callback(BankResponse(false, errorMessage = message)) + callback(BankResponse(false, internalError = message)) } else { sendChangeTanMediumMessage(bank, newActiveTanMedium, enteredAtc, callback) @@ -526,7 +526,7 @@ open class FinTsJobExecutor( } else { val errorMessage = "There's no last action (like retrieve account transactions, transfer money, ...) to re-send with new TAN method. Probably an internal programming error." // TODO: translate - callback(BankResponse(false, errorMessage = errorMessage)) // should never come to this + callback(BankResponse(false, internalError = errorMessage)) // should never come to this } } @@ -627,7 +627,7 @@ open class FinTsJobExecutor( if (getBankInfoResponse.successful == false) { callback(getBankInfoResponse) } else if (bank.tanMethodSupportedByBank.isEmpty() || bank.supportedJobs.isEmpty()) { - callback(BankResponse(false, errorMessage = + callback(BankResponse(false, internalError = "Could not retrieve basic bank data like supported tan methods or supported jobs")) // TODO: translate // TODO: add as messageToShowToUser } else { callback(BankResponse(true)) @@ -661,7 +661,7 @@ open class FinTsJobExecutor( val noTanMethodSelected = !!!bank.isTanMethodSelected val errorMessage = if (noTanMethodSelected) "User did not select a TAN method" else null // TODO: translate - return BankResponse(true, noTanMethodSelected = noTanMethodSelected, errorMessage = errorMessage) + return BankResponse(true, noTanMethodSelected = noTanMethodSelected, internalError = errorMessage) } open fun getUsersTanMethod(bank: BankData, done: (Boolean) -> Unit) { diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/RequestExecutor.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/RequestExecutor.kt index 2b335b0e..6798af2a 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/RequestExecutor.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/RequestExecutor.kt @@ -48,7 +48,7 @@ open class RequestExecutor( if (message.createdMessage == null) { log.error("Could not create FinTS message to be sent to bank. isJobAllowed ${message.isJobAllowed}, isJobVersionSupported = ${message.isJobVersionSupported}," + "allowedVersions = ${message.allowedVersions}, supportedVersions = ${message.supportedVersions}.") - callback(BankResponse(false, messageThatCouldNotBeCreated = message, errorMessage = "Could not create FinTS message to be sent to bank")) // TODO: translate + callback(BankResponse(false, messageThatCouldNotBeCreated = message, internalError = "Could not create FinTS message to be sent to bank")) // TODO: translate } else { getAndHandleResponseForMessage(message.createdMessage, dialogContext) { response -> @@ -130,7 +130,7 @@ open class RequestExecutor( } catch (e: Exception) { logError("Could not decode responseBody:\r\n'$responseBody'", dialogContext, e) - return BankResponse(false, errorMessage = e.getInnerExceptionMessage()) + return BankResponse(false, internalError = e.getInnerExceptionMessage()) } } else { @@ -138,7 +138,7 @@ open class RequestExecutor( logError("Request to $bank (${bank.finTs3ServerAddress}) failed", dialogContext, webResponse.error) } - return BankResponse(false, errorMessage = webResponse.error?.getInnerExceptionMessage()) + return BankResponse(false, internalError = webResponse.error?.getInnerExceptionMessage()) } protected open fun decodeBase64Response(responseBody: String): String { diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/BankResponse.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/BankResponse.kt index 38288327..56f442c4 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/BankResponse.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/BankResponse.kt @@ -14,9 +14,9 @@ open class BankResponse( val receivedSegments: List = listOf(), /** - * When a serious error occurred during web request or response parsing. + * A fints4k internal error like an error occurred during web request or response parsing. */ - val errorMessage: String? = null, + val internalError: String? = null, val noTanMethodSelected: Boolean = false, val messageThatCouldNotBeCreated: MessageBuilderResult? = null // i think that can be removed ) { @@ -25,7 +25,7 @@ open class BankResponse( get() = messageThatCouldNotBeCreated == null open val responseContainsErrors: Boolean - get() = errorMessage == null && + get() = internalError == null && (messageFeedback?.isError == true || isPinLocked) open val isPinLocked: Boolean @@ -59,7 +59,8 @@ open class BankResponse( open var tanRequiredButWeWereToldToAbortIfSo = false open val successful: Boolean - get() = noTanMethodSelected == false && couldCreateMessage && didReceiveResponse + get() = internalError == null && + noTanMethodSelected == false && couldCreateMessage && didReceiveResponse && responseContainsErrors == false && wrongCredentialsEntered == false && tanRequiredButUserDidNotEnterOne == false && tanRequiredButWeWereToldToAbortIfSo == false @@ -157,7 +158,7 @@ open class BankResponse( return formattedResponse } - return "Error: $errorMessage\n$formattedResponse" + return "Error: $internalError\n$formattedResponse" } } \ No newline at end of file diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/ResponseParser.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/ResponseParser.kt index 644db49b..d32c25f3 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/ResponseParser.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/ResponseParser.kt @@ -56,7 +56,7 @@ open class ResponseParser( } catch (e: Exception) { logError("Could not parse response '$response'", e) - return BankResponse(true, response, errorMessage = e.getInnerExceptionMessage()) + return BankResponse(true, response, internalError = e.getInnerExceptionMessage()) } } diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/client/FinTsClientResponse.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/client/FinTsClientResponse.kt index 1c4fcab3..dc597b25 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/client/FinTsClientResponse.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/client/FinTsClientResponse.kt @@ -13,12 +13,12 @@ open class FinTsClientResponse( open val isStrongAuthenticationRequired: Boolean, open val tanRequired: TanResponse? = null, - open val errorsToShowToUser: List = listOf(), - /** - * When a serious error occurred during web request or response parsing. + * A fints4k internal error like an error occurred during web request or response parsing. */ - open val errorMessage: String? = null, + open val internalError: String? = null, + + open val errorMessagesFromBank: List = listOf(), open val wrongCredentialsEntered: Boolean = false, @@ -35,8 +35,8 @@ open class FinTsClientResponse( constructor(response: BankResponse) : this(response.successful, response.noTanMethodSelected, - response.isStrongAuthenticationRequired, response.tanResponse, response.errorsToShowToUser, - response.errorMessage, response.wrongCredentialsEntered, + response.isStrongAuthenticationRequired, response.tanResponse, response.internalError, + response.errorsToShowToUser, response.wrongCredentialsEntered, response.tanRequiredButUserDidNotEnterOne, response.tanRequiredButWeWereToldToAbortIfSo, response.messageThatCouldNotBeCreated?.isJobAllowed ?: true, response.messageThatCouldNotBeCreated?.isJobVersionSupported ?: true, @@ -44,6 +44,15 @@ open class FinTsClientResponse( response.messageThatCouldNotBeCreated?.supportedVersions ?: listOf()) + open val errorMessage: String? + get() = internalError + ?: if (errorMessagesFromBank.isNotEmpty()) errorMessagesFromBank.joinToString("\n") + else null + + open val didBankReturnError: Boolean + get() = internalError == null && errorMessagesFromBank.isNotEmpty() + + override fun toString(): String { if (noTanMethodSelected) { return "Error: No TAN method selected" diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/client/GetTransactionsResponse.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/client/GetTransactionsResponse.kt index a18e8c4e..713339a0 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/client/GetTransactionsResponse.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/client/GetTransactionsResponse.kt @@ -19,8 +19,8 @@ open class GetTransactionsResponse( && retrievedData.none { it.account.supportsRetrievingAccountTransactions && it.successfullyRetrievedData == false } // TODO: remove again if then in AddAccountResponse errors get displayed that should or extract getRetrievingTransactionsError() and override in AddAccountResponse - override val errorMessage: String? - get() = super.errorMessage + override val internalError: String? + get() = super.internalError ?: retrievedData.mapNotNull { it.errorMessage }.firstOrNull() diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/client/GetUserTanMethodsResponse.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/client/GetUserTanMethodsResponse.kt index 7ecd6c62..aade8590 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/client/GetUserTanMethodsResponse.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/client/GetUserTanMethodsResponse.kt @@ -6,7 +6,7 @@ import net.dankito.banking.fints.response.ResponseParser open class GetUserTanMethodsResponse(bankResponse: BankResponse) : BankResponse(bankResponse.didReceiveResponse, bankResponse.receivedResponse, bankResponse.receivedSegments, - bankResponse.errorMessage, bankResponse.noTanMethodSelected, bankResponse.messageThatCouldNotBeCreated) { + bankResponse.internalError, bankResponse.noTanMethodSelected, bankResponse.messageThatCouldNotBeCreated) { /** * comdirect sends "9955::Unzulässiges TAN-Verfahren." even though '999' is a valid TAN method diff --git a/fints4k/src/commonTest/kotlin/net/dankito/banking/fints/response/ResponseParserTest.kt b/fints4k/src/commonTest/kotlin/net/dankito/banking/fints/response/ResponseParserTest.kt index 1ac45169..6c69c463 100644 --- a/fints4k/src/commonTest/kotlin/net/dankito/banking/fints/response/ResponseParserTest.kt +++ b/fints4k/src/commonTest/kotlin/net/dankito/banking/fints/response/ResponseParserTest.kt @@ -1302,7 +1302,7 @@ class ResponseParserTest : FinTsTestBase() { private fun assertCouldParseResponse(result: BankResponse) { expect(result.successful).isTrue() expect(result.responseContainsErrors).isFalse() - expect(result.errorMessage).toBe(null) + expect(result.internalError).toBe(null) expect(result.errorsToShowToUser).isEmpty() expect(result.receivedResponse).notToBeNull() } diff --git a/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/model/responses/AddAccountResponse.kt b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/model/responses/AddAccountResponse.kt index 7f8df8a3..9d440d5e 100644 --- a/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/model/responses/AddAccountResponse.kt +++ b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/model/responses/AddAccountResponse.kt @@ -7,9 +7,10 @@ open class AddAccountResponse( open val bank: TypedBankData, retrievedData: List = listOf(), errorToShowToUser: String? = null, + didBankReturnError: Boolean = false, wrongCredentialsEntered: Boolean = false, userCancelledAction: Boolean = false -) : GetTransactionsResponse(retrievedData, errorToShowToUser, wrongCredentialsEntered, userCancelledAction) { +) : GetTransactionsResponse(retrievedData, errorToShowToUser, didBankReturnError, wrongCredentialsEntered, userCancelledAction) { constructor(bank: TypedBankData, errorToShowToUser: String?) : this(bank, listOf(), errorToShowToUser) diff --git a/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/model/responses/BankingClientResponse.kt b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/model/responses/BankingClientResponse.kt index 3a1469e9..a9b70791 100644 --- a/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/model/responses/BankingClientResponse.kt +++ b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/model/responses/BankingClientResponse.kt @@ -4,6 +4,7 @@ package net.dankito.banking.ui.model.responses open class BankingClientResponse( open val successful: Boolean, open val errorToShowToUser: String?, + open val didBankReturnError: Boolean, open val wrongCredentialsEntered: Boolean = false, open val userCancelledAction: Boolean = false // TODO: not implemented in hbci4jBankingClient yet ) { diff --git a/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/model/responses/GetTransactionsResponse.kt b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/model/responses/GetTransactionsResponse.kt index 0508f044..8de4e1ed 100644 --- a/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/model/responses/GetTransactionsResponse.kt +++ b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/model/responses/GetTransactionsResponse.kt @@ -7,10 +7,11 @@ import net.dankito.banking.ui.model.TypedBankAccount open class GetTransactionsResponse( open val retrievedData: List, errorToShowToUser: String?, + didBankReturnError: Boolean = false, wrongCredentialsEntered: Boolean = false, userCancelledAction: Boolean = false, open val tanRequiredButWeWereToldToAbortIfSo: Boolean = false -) : BankingClientResponse(true /* any value */, errorToShowToUser, wrongCredentialsEntered, userCancelledAction) { +) : BankingClientResponse(true /* any value */, errorToShowToUser, didBankReturnError, wrongCredentialsEntered, userCancelledAction) { constructor(account: TypedBankAccount, errorToShowToUser: String) : this(RetrievedAccountData.unsuccessfulList(account), errorToShowToUser) diff --git a/ui/fints4kBankingClient/src/commonMain/kotlin/net/dankito/banking/mapper/fints4kModelMapper.kt b/ui/fints4kBankingClient/src/commonMain/kotlin/net/dankito/banking/mapper/fints4kModelMapper.kt index 84bc90d6..4223c1e6 100644 --- a/ui/fints4kBankingClient/src/commonMain/kotlin/net/dankito/banking/mapper/fints4kModelMapper.kt +++ b/ui/fints4kBankingClient/src/commonMain/kotlin/net/dankito/banking/mapper/fints4kModelMapper.kt @@ -24,18 +24,18 @@ open class fints4kModelMapper(protected val modelCreator: IModelCreator) { open fun mapResponse(response: FinTsClientResponse): BankingClientResponse { - return BankingClientResponse(response.successful, mapErrorToShowToUser(response), response.wrongCredentialsEntered, response.userCancelledAction) + return BankingClientResponse(response.successful, response.errorMessage, response.didBankReturnError, response.wrongCredentialsEntered, response.userCancelledAction) } open fun mapResponse(bank: TypedBankData, response: net.dankito.banking.fints.response.client.AddAccountResponse): AddAccountResponse { - return AddAccountResponse(bank, map(bank, response.retrievedData), mapErrorToShowToUser(response), response.wrongCredentialsEntered, response.userCancelledAction) + return AddAccountResponse(bank, map(bank, response.retrievedData), response.errorMessage, response.didBankReturnError, response.wrongCredentialsEntered, response.userCancelledAction) } open fun mapResponse(account: TypedBankAccount, response: net.dankito.banking.fints.response.client.GetTransactionsResponse): GetTransactionsResponse { return GetTransactionsResponse(map(account.bank as TypedBankData, response.retrievedData), - mapErrorToShowToUser(response), response.wrongCredentialsEntered, response.userCancelledAction, response.tanRequiredButWeWereToldToAbortIfSo) + response.errorMessage, response.didBankReturnError, response.wrongCredentialsEntered, response.userCancelledAction, response.tanRequiredButWeWereToldToAbortIfSo) } open fun map(bank: TypedBankData, retrievedData: List): List { @@ -61,13 +61,6 @@ open class fints4kModelMapper(protected val modelCreator: IModelCreator) { ) } - open fun mapErrorToShowToUser(response: FinTsClientResponse): String? { - val errorMessage = response.errorMessage - - return errorMessage ?: - if (response.errorsToShowToUser.isEmpty()) null else response.errorsToShowToUser.joinToString("\n") // TODO: find a better way to choose which of these error messages to show - } - open fun mapBank(bank: TypedBankData, fintsBank: BankData) { bank.bankCode = fintsBank.bankCode