From 9c6339492216eead4dd59897cadaa5298bd8e288 Mon Sep 17 00:00:00 2001 From: dankito Date: Sun, 18 Apr 2021 01:23:37 +0200 Subject: [PATCH] Fixed filtering out accounts for which no transactions have been retrieved (otherwise .first() throws an exception) --- .../net/dankito/banking/fints/rest/mapper/DtoMapper.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/rest/fints4kRest/src/main/kotlin/net/dankito/banking/fints/rest/mapper/DtoMapper.kt b/rest/fints4kRest/src/main/kotlin/net/dankito/banking/fints/rest/mapper/DtoMapper.kt index 84acea4f..b54e4059 100644 --- a/rest/fints4kRest/src/main/kotlin/net/dankito/banking/fints/rest/mapper/DtoMapper.kt +++ b/rest/fints4kRest/src/main/kotlin/net/dankito/banking/fints/rest/mapper/DtoMapper.kt @@ -44,10 +44,14 @@ open class DtoMapper { throw InternalServerErrorException("Could not fetch account transactions. Either TAN hasn't been entered or developers made a mistake.") } - return GetAccountsTransactionsResponseDto(accountsTransactions.map { map(it) }) + return GetAccountsTransactionsResponseDto(accountsTransactions.mapNotNull { map(it) }) // TODO: is this correct removing accounts from result for which no transactions have been retrieved? } - open fun map(accountTransactions: GetTransactionsResponse): GetAccountTransactionsResponseDto { + open fun map(accountTransactions: GetTransactionsResponse): GetAccountTransactionsResponseDto? { + if (accountTransactions.retrievedData.isEmpty()) { + return null + } + val retrievedData = accountTransactions.retrievedData.first() val balance = mapNullable(retrievedData.balance) val bookedTransactions = map(retrievedData.bookedTransactions)