diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/config/Internationalization.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/config/Internationalization.kt index f4566f7..159a684 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/config/Internationalization.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/config/Internationalization.kt @@ -13,6 +13,8 @@ object Internationalization { const val ErrorTransferMoney = "Überweisung konnte nicht ausgeführt werden" + const val SaveToDatabase = "Daten konnten nicht in der Datenbank gespeichert werden" + const val ErrorBiometricAuthentication = "Biometrische Authentifizierung fehlgeschlagen" diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/dialogs/ApplicationErrorDialog.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/dialogs/ApplicationErrorDialog.kt index e1900d1..44b9f49 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/dialogs/ApplicationErrorDialog.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/dialogs/ApplicationErrorDialog.kt @@ -11,6 +11,7 @@ fun ApplicationErrorDialog(error: ApplicationError, onDismiss: (() -> Unit)? = n ErroneousAction.AddAccount -> Internationalization.ErrorAddAccount ErroneousAction.UpdateAccountTransactions -> Internationalization.ErrorUpdateAccountTransactions ErroneousAction.TransferMoney -> Internationalization.ErrorTransferMoney + ErroneousAction.SaveToDatabase -> Internationalization.SaveToDatabase ErroneousAction.BiometricAuthentication -> Internationalization.ErrorBiometricAuthentication } diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/model/error/ErroneousAction.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/model/error/ErroneousAction.kt index c7ea13c..2bf4454 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/model/error/ErroneousAction.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/model/error/ErroneousAction.kt @@ -7,5 +7,7 @@ enum class ErroneousAction { TransferMoney, + SaveToDatabase, + BiometricAuthentication } \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/BankingService.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/BankingService.kt index e9a0fea..5dbe4e2 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/BankingService.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/BankingService.kt @@ -129,7 +129,7 @@ class BankingService( notifyBanksListUpdated() } catch (e: Throwable) { -// showAndLogError("Could not update bank $bank", e) + showAndLogError(ErroneousAction.SaveToDatabase, "Could not update bank $account", "Bankzugangsdaten konnten nicht aktualisisert werden", e) } } @@ -142,6 +142,7 @@ class BankingService( updateBanksInUi(uiState.banks.value.toMutableList().also { it.remove(bank) }) } catch (e: Throwable) { log.error(e) { "Could not delete bank ${bank.displayName}" } + showAndLogError(ErroneousAction.SaveToDatabase, "Could not delete bank ${bank.displayName}", "Fehler beim Löschen der Bankzugangsdaten für ${bank.displayName}", e) } } @@ -166,14 +167,12 @@ class BankingService( if (response.type == ResponseType.Success && response.data != null) { handleSuccessfulGetAccountDataResponse(response.data!!) } else { - handleUnsuccessfulBankingClientResponse(BankingClientAction.AddAccount, response) + handleUnsuccessfulBankingClientResponse(BankingClientAction.AddAccount, bank.name, response) } return response.type == ResponseType.Success } catch (e: Throwable) { - log.error(e) { "Could not add account for ${bank.name} $loginName" } - - uiState.applicationErrorOccurred(ErroneousAction.AddAccount, null, e) + showAndLogError(ErroneousAction.AddAccount, "Could not add account for ${bank.name} $loginName", "Konto für ${bank.name} konnte nicht hinzugefügt werden", e) return false } @@ -226,7 +225,7 @@ class BankingService( if (response.type == ResponseType.Success && response.data != null) { handleSuccessfulUpdateAccountTransactionsResponse(bank, response.data!!) } else { - handleUnsuccessfulBankingClientResponse(BankingClientAction.UpdateAccountTransactions, response) + handleUnsuccessfulBankingClientResponse(BankingClientAction.UpdateAccountTransactions, bankAccount?.displayName ?: bank.displayName, response) } } catch (e: Throwable) { log.error(e) { "Could not update account transactions for $bank" } @@ -352,7 +351,7 @@ class BankingService( )) if (response.error != null) { - handleUnsuccessfulBankingClientResponse(BankingClientAction.TransferMoney, response) + handleUnsuccessfulBankingClientResponse(BankingClientAction.TransferMoney, account.displayName, response) } else if (response.type == ResponseType.Success) { uiState.dispatchTransferredMoney(TransferredMoneyEvent(recipientName, amount, currency)) @@ -363,8 +362,8 @@ class BankingService( } - private fun handleUnsuccessfulBankingClientResponse(action: BankingClientAction, response: Response<*>) { - log.error { "$action was not successful: $response" } + private fun handleUnsuccessfulBankingClientResponse(action: BankingClientAction, accountOrBankName: String, response: Response<*>) { + log.error { "$action was not successful for $accountOrBankName: $response" } response.error?.let { error -> if (error.type != ErrorType.UserCancelledAction) { // the user knows that she cancelled the action @@ -391,6 +390,12 @@ class BankingService( } } + private fun showAndLogError(action: ErroneousAction, logMessage: String, messageToShowToUser: String? = null, exception: Throwable? = null) { + log.error(exception) { logMessage } + + uiState.applicationErrorOccurred(action, messageToShowToUser, exception) + } + private suspend fun readTransactionsFromCsv(): List { val csv = Res.readBytes("files/transactions.csv").decodeToString()