diff --git a/common/src/commonMain/kotlin/net/dankito/utils/multiplatform/CommonExtensions.kt b/common/src/commonMain/kotlin/net/dankito/utils/multiplatform/CommonExtensions.kt index f8152c6b..28b59f4e 100644 --- a/common/src/commonMain/kotlin/net/dankito/utils/multiplatform/CommonExtensions.kt +++ b/common/src/commonMain/kotlin/net/dankito/utils/multiplatform/CommonExtensions.kt @@ -22,6 +22,27 @@ fun Date.isBeforeOrEquals(other: Date): Boolean { } +fun Throwable.getAllExceptionMessagesJoined(maxDepth: Int = 5): String { + return getAllExceptionMessages(maxDepth).joinToString("\n") +} + +fun Throwable.getAllExceptionMessages(maxDepth: Int = 5): List { + val exceptionMessages = mutableSetOf() + var innerException: Throwable? = this + var depth = 0 + + do { + innerException?.message?.let { message -> + exceptionMessages.add("${innerException!!::class.simpleName}: $message") + } + + innerException = innerException?.cause + depth++ + } while (innerException != null && depth < maxDepth) + + return exceptionMessages.toList() +} + fun Throwable.getInnerExceptionMessage(maxDepth: Int = 3): String { return this.getInnerException(maxDepth).message ?: "" } 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 6798af2a..a9fe9c21 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/RequestExecutor.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/RequestExecutor.kt @@ -13,7 +13,7 @@ import net.dankito.banking.fints.util.PureKotlinBase64Service import net.dankito.banking.fints.webclient.IWebClient import net.dankito.banking.fints.webclient.KtorWebClient import net.dankito.banking.fints.webclient.WebClientResponse -import net.dankito.utils.multiplatform.getInnerExceptionMessage +import net.dankito.utils.multiplatform.getAllExceptionMessagesJoined import net.dankito.utils.multiplatform.log.Logger import net.dankito.utils.multiplatform.log.LoggerFactory @@ -130,7 +130,7 @@ open class RequestExecutor( } catch (e: Exception) { logError("Could not decode responseBody:\r\n'$responseBody'", dialogContext, e) - return BankResponse(false, internalError = e.getInnerExceptionMessage()) + return BankResponse(false, internalError = e.getAllExceptionMessagesJoined()) } } else { @@ -138,7 +138,7 @@ open class RequestExecutor( logError("Request to $bank (${bank.finTs3ServerAddress}) failed", dialogContext, webResponse.error) } - return BankResponse(false, internalError = webResponse.error?.getInnerExceptionMessage()) + return BankResponse(false, internalError = webResponse.error?.getAllExceptionMessagesJoined()) } protected open fun decodeBase64Response(responseBody: String): String { 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 d32c25f3..ccb9fb68 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 @@ -21,7 +21,7 @@ import net.dankito.banking.fints.model.Money import net.dankito.banking.fints.response.segments.* import net.dankito.banking.fints.util.MessageUtils import net.dankito.utils.multiplatform.Date -import net.dankito.utils.multiplatform.getInnerExceptionMessage +import net.dankito.utils.multiplatform.getAllExceptionMessagesJoined import net.dankito.utils.multiplatform.log.LoggerFactory @@ -56,7 +56,7 @@ open class ResponseParser( } catch (e: Exception) { logError("Could not parse response '$response'", e) - return BankResponse(true, response, internalError = e.getInnerExceptionMessage()) + return BankResponse(true, response, internalError = e.getAllExceptionMessagesJoined()) } } diff --git a/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/presenter/BankingPresenter.kt b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/presenter/BankingPresenter.kt index b07f9948..22c923d8 100644 --- a/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/presenter/BankingPresenter.kt +++ b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/presenter/BankingPresenter.kt @@ -35,7 +35,6 @@ import net.dankito.banking.util.extraction.NoOpTextExtractorRegistry import net.codinux.banking.tools.epcqrcode.* import net.dankito.banking.service.testaccess.TestAccessBankingClientCreator import net.dankito.utils.multiplatform.* -import net.dankito.utils.multiplatform.getInnerExceptionMessage import net.dankito.utils.multiplatform.log.LoggerFactory import net.dankito.utils.multiplatform.os.DeviceInfo import net.dankito.utils.multiplatform.os.DeviceInfoRetriever @@ -864,7 +863,7 @@ open class BankingPresenter( log.info("Response: $response") } catch (e: Exception) { - log.error("Could not create ticket directly: ${e.getInnerExceptionMessage()}", e) + log.error("Could not create ticket directly: ${e.getAllExceptionMessagesJoined()}", e) } } }