From 26cc2088ad45311d2893fee46cbf47828e8ebd9e Mon Sep 17 00:00:00 2001 From: dankito Date: Sun, 6 Dec 2020 16:47:59 +0100 Subject: [PATCH] Catching errors while parsing credit card transactions --- .../banking/fints/response/ResponseParser.kt | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) 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 583b469b..5e20e202 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 @@ -690,21 +690,27 @@ open class ResponseParser( return ReceivedCreditCardTransactionsAndBalance( balance, - transactionsDataElementGroups.map { mapCreditCardTransaction(it) }, + transactionsDataElementGroups.mapNotNull { mapCreditCardTransaction(it) }, segment ) } - protected open fun mapCreditCardTransaction(transactionDataElementGroup: String): CreditCardTransaction { - val dataElements = getDataElements(transactionDataElementGroup) + protected open fun mapCreditCardTransaction(transactionDataElementGroup: String): CreditCardTransaction? { + try { + val dataElements = getDataElements(transactionDataElementGroup) - val bookingDate = parseDate(dataElements[1]) - val valueDate = parseDate(dataElements[2]) - val amount = parseCreditCardAmount(dataElements.subList(8, 11)) - val otherPartyName = parseString(dataElements[11]) - val isCleared = parseBoolean(dataElements[20]) + val bookingDate = parseDate(dataElements[1]) + val valueDate = parseDate(dataElements[2]) + val amount = parseCreditCardAmount(dataElements.subList(8, 11)) + val otherPartyName = parseString(dataElements[11]) + val isCleared = parseBoolean(dataElements[20]) - return CreditCardTransaction(amount, otherPartyName, bookingDate, valueDate, isCleared) + return CreditCardTransaction(amount, otherPartyName, bookingDate, valueDate, isCleared) + } catch (e: Exception) { + log.error("Could not parse Credit card transaction '$transactionDataElementGroup'", e) + } + + return null } private fun parseCreditCardAmount(amountDataElements: List): Money {