Implemented telling user when saving to db failed

This commit is contained in:
dankito 2024-09-23 23:30:11 +02:00
parent 5a0ade46b2
commit c6f4b6d250
4 changed files with 19 additions and 9 deletions

View File

@ -13,6 +13,8 @@ object Internationalization {
const val ErrorTransferMoney = "Überweisung konnte nicht ausgeführt werden" 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" const val ErrorBiometricAuthentication = "Biometrische Authentifizierung fehlgeschlagen"

View File

@ -11,6 +11,7 @@ fun ApplicationErrorDialog(error: ApplicationError, onDismiss: (() -> Unit)? = n
ErroneousAction.AddAccount -> Internationalization.ErrorAddAccount ErroneousAction.AddAccount -> Internationalization.ErrorAddAccount
ErroneousAction.UpdateAccountTransactions -> Internationalization.ErrorUpdateAccountTransactions ErroneousAction.UpdateAccountTransactions -> Internationalization.ErrorUpdateAccountTransactions
ErroneousAction.TransferMoney -> Internationalization.ErrorTransferMoney ErroneousAction.TransferMoney -> Internationalization.ErrorTransferMoney
ErroneousAction.SaveToDatabase -> Internationalization.SaveToDatabase
ErroneousAction.BiometricAuthentication -> Internationalization.ErrorBiometricAuthentication ErroneousAction.BiometricAuthentication -> Internationalization.ErrorBiometricAuthentication
} }

View File

@ -7,5 +7,7 @@ enum class ErroneousAction {
TransferMoney, TransferMoney,
SaveToDatabase,
BiometricAuthentication BiometricAuthentication
} }

View File

@ -129,7 +129,7 @@ class BankingService(
notifyBanksListUpdated() notifyBanksListUpdated()
} catch (e: Throwable) { } 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) }) updateBanksInUi(uiState.banks.value.toMutableList().also { it.remove(bank) })
} catch (e: Throwable) { } catch (e: Throwable) {
log.error(e) { "Could not delete bank ${bank.displayName}" } 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) { if (response.type == ResponseType.Success && response.data != null) {
handleSuccessfulGetAccountDataResponse(response.data!!) handleSuccessfulGetAccountDataResponse(response.data!!)
} else { } else {
handleUnsuccessfulBankingClientResponse(BankingClientAction.AddAccount, response) handleUnsuccessfulBankingClientResponse(BankingClientAction.AddAccount, bank.name, response)
} }
return response.type == ResponseType.Success return response.type == ResponseType.Success
} catch (e: Throwable) { } catch (e: Throwable) {
log.error(e) { "Could not add account for ${bank.name} $loginName" } showAndLogError(ErroneousAction.AddAccount, "Could not add account for ${bank.name} $loginName", "Konto für ${bank.name} konnte nicht hinzugefügt werden", e)
uiState.applicationErrorOccurred(ErroneousAction.AddAccount, null, e)
return false return false
} }
@ -226,7 +225,7 @@ class BankingService(
if (response.type == ResponseType.Success && response.data != null) { if (response.type == ResponseType.Success && response.data != null) {
handleSuccessfulUpdateAccountTransactionsResponse(bank, response.data!!) handleSuccessfulUpdateAccountTransactionsResponse(bank, response.data!!)
} else { } else {
handleUnsuccessfulBankingClientResponse(BankingClientAction.UpdateAccountTransactions, response) handleUnsuccessfulBankingClientResponse(BankingClientAction.UpdateAccountTransactions, bankAccount?.displayName ?: bank.displayName, response)
} }
} catch (e: Throwable) { } catch (e: Throwable) {
log.error(e) { "Could not update account transactions for $bank" } log.error(e) { "Could not update account transactions for $bank" }
@ -352,7 +351,7 @@ class BankingService(
)) ))
if (response.error != null) { if (response.error != null) {
handleUnsuccessfulBankingClientResponse(BankingClientAction.TransferMoney, response) handleUnsuccessfulBankingClientResponse(BankingClientAction.TransferMoney, account.displayName, response)
} else if (response.type == ResponseType.Success) { } else if (response.type == ResponseType.Success) {
uiState.dispatchTransferredMoney(TransferredMoneyEvent(recipientName, amount, currency)) uiState.dispatchTransferredMoney(TransferredMoneyEvent(recipientName, amount, currency))
@ -363,8 +362,8 @@ class BankingService(
} }
private fun handleUnsuccessfulBankingClientResponse(action: BankingClientAction, response: Response<*>) { private fun handleUnsuccessfulBankingClientResponse(action: BankingClientAction, accountOrBankName: String, response: Response<*>) {
log.error { "$action was not successful: $response" } log.error { "$action was not successful for $accountOrBankName: $response" }
response.error?.let { error -> response.error?.let { error ->
if (error.type != ErrorType.UserCancelledAction) { // the user knows that she cancelled the action 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<AccountTransaction> { private suspend fun readTransactionsFromCsv(): List<AccountTransaction> {
val csv = Res.readBytes("files/transactions.csv").decodeToString() val csv = Res.readBytes("files/transactions.csv").decodeToString()