Implemented getAllExceptionMessages() to list all messages in exception hierarchy
This commit is contained in:
parent
3344b6d816
commit
c82611ad6c
|
@ -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 {
|
||||
return this.getInnerException(maxDepth).message ?: ""
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue