Implemented getAllExceptionMessages() to list all messages in exception hierarchy

This commit is contained in:
dankito 2021-11-01 17:36:52 +01:00
parent 3344b6d816
commit c82611ad6c
4 changed files with 27 additions and 7 deletions

View File

@ -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<String> {
val exceptionMessages = mutableSetOf<String>()
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 { fun Throwable.getInnerExceptionMessage(maxDepth: Int = 3): String {
return this.getInnerException(maxDepth).message ?: "" return this.getInnerException(maxDepth).message ?: ""
} }

View File

@ -13,7 +13,7 @@ import net.dankito.banking.fints.util.PureKotlinBase64Service
import net.dankito.banking.fints.webclient.IWebClient import net.dankito.banking.fints.webclient.IWebClient
import net.dankito.banking.fints.webclient.KtorWebClient import net.dankito.banking.fints.webclient.KtorWebClient
import net.dankito.banking.fints.webclient.WebClientResponse 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.Logger
import net.dankito.utils.multiplatform.log.LoggerFactory import net.dankito.utils.multiplatform.log.LoggerFactory
@ -130,7 +130,7 @@ open class RequestExecutor(
} catch (e: Exception) { } catch (e: Exception) {
logError("Could not decode responseBody:\r\n'$responseBody'", dialogContext, e) logError("Could not decode responseBody:\r\n'$responseBody'", dialogContext, e)
return BankResponse(false, internalError = e.getInnerExceptionMessage()) return BankResponse(false, internalError = e.getAllExceptionMessagesJoined())
} }
} }
else { else {
@ -138,7 +138,7 @@ open class RequestExecutor(
logError("Request to $bank (${bank.finTs3ServerAddress}) failed", dialogContext, webResponse.error) 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 { protected open fun decodeBase64Response(responseBody: String): String {

View File

@ -21,7 +21,7 @@ import net.dankito.banking.fints.model.Money
import net.dankito.banking.fints.response.segments.* import net.dankito.banking.fints.response.segments.*
import net.dankito.banking.fints.util.MessageUtils import net.dankito.banking.fints.util.MessageUtils
import net.dankito.utils.multiplatform.Date 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 import net.dankito.utils.multiplatform.log.LoggerFactory
@ -56,7 +56,7 @@ open class ResponseParser(
} catch (e: Exception) { } catch (e: Exception) {
logError("Could not parse response '$response'", e) logError("Could not parse response '$response'", e)
return BankResponse(true, response, internalError = e.getInnerExceptionMessage()) return BankResponse(true, response, internalError = e.getAllExceptionMessagesJoined())
} }
} }

View File

@ -35,7 +35,6 @@ import net.dankito.banking.util.extraction.NoOpTextExtractorRegistry
import net.codinux.banking.tools.epcqrcode.* import net.codinux.banking.tools.epcqrcode.*
import net.dankito.banking.service.testaccess.TestAccessBankingClientCreator import net.dankito.banking.service.testaccess.TestAccessBankingClientCreator
import net.dankito.utils.multiplatform.* import net.dankito.utils.multiplatform.*
import net.dankito.utils.multiplatform.getInnerExceptionMessage
import net.dankito.utils.multiplatform.log.LoggerFactory import net.dankito.utils.multiplatform.log.LoggerFactory
import net.dankito.utils.multiplatform.os.DeviceInfo import net.dankito.utils.multiplatform.os.DeviceInfo
import net.dankito.utils.multiplatform.os.DeviceInfoRetriever import net.dankito.utils.multiplatform.os.DeviceInfoRetriever
@ -864,7 +863,7 @@ open class BankingPresenter(
log.info("Response: $response") log.info("Response: $response")
} catch (e: Exception) { } catch (e: Exception) {
log.error("Could not create ticket directly: ${e.getInnerExceptionMessage()}", e) log.error("Could not create ticket directly: ${e.getAllExceptionMessagesJoined()}", e)
} }
} }
} }