taler-ios

iOS apps for GNU Taler (wallet)
Log | Files | Refs | README | LICENSE

commit 1226ff53697984162bea522316accc8baf39734e
parent 854145e912418b24831b1ea5ffaac4b98aa39012
Author: Marc Stibane <marc@taler.net>
Date:   Wed, 18 Nov 2026 12:16:27 +0100

expected errors are no "Internal core error"

Diffstat:
MTalerWallet1/Views/Main/ErrorView.swift | 116+++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------
1 file changed, 75 insertions(+), 41 deletions(-)

diff --git a/TalerWallet1/Views/Main/ErrorView.swift b/TalerWallet1/Views/Main/ErrorView.swift @@ -102,29 +102,6 @@ enum ErrorData { } struct ErrorView: View { - - /// wallet-core errors that are expected outcomes, rather than faults, keyed by `TalerErrorCode`. - static func titleForExpected(code: Int) -> String? { - switch code { - case 7000, // WALLET_EXCHANGE_PROTOCOL_VERSION_INCOMPATIBLE - 7017: // WALLET_BANK_INTEGRATION_PROTOCOL_VERSION_INCOMPATIBLE - String(localized: "Incompatible version", - comment: "error title: the server speaks a protocol this app does not") - case 7041: // WALLET_PEER_PULL_DEBIT_PURSE_GONE - String(localized: "Invoice expired", - comment: "error title: the payer waited too long") - case 7054: // WALLET_KYC_LIMIT_EXCEEDED - String(localized: "Limit exceeded", - comment: "error title: the payment service refused the amount") - case 7055: // WALLET_NO_SUITABLE_EXCHANGE - String(localized: "No suitable payment service", - comment: "error title: no exchange can serve this request") - case 7064: // WALLET_CONTRACT_TERMS_UNSUPPORTED - String(localized: "Transaction Error") - default: nil - } - } - let stack: CallStack? var title: String var exclam: Bool @@ -145,6 +122,67 @@ struct ErrorView: View { self.onDismiss = onDismiss } + /// wallet-core errors that are expected outcomes, rather than faults, keyed by `TalerErrorCode` from taler-error-codes.ts. + static func titleForExpected(code: Int) -> String? { + switch code { + case 7000, // WALLET_EXCHANGE_PROTOCOL_VERSION_INCOMPATIBLE + 7017: // WALLET_BANK_INTEGRATION_PROTOCOL_VERSION_INCOMPATIBLE + String(localized: "Incompatible protocol version", + comment: "error title: 7000,7017: the server speaks a protocol this app does not") + // 7002, 7003, 7005, 7013 and 7032 are mapped to INTERNET ERROR +// case 7002: // WALLET_RECEIVED_MALFORMED_RESPONSE +// String(localized: "Bad response from server", +// comment: "error title: 7002: the server sent an invalid response") +// case 7003: // WALLET_NETWORK_ERROR +// String(localized: "", +// comment: "error title: 7003: ") +// case 7005: // WALLET_UNEXPECTED_REQUEST_ERROR +// String(localized: "", +// comment: "error title: 7005: ") +// case 7013: // WALLET_HTTP_REQUEST_GENERIC_TIMEOUT +// String(localized: "Network timeout", +// comment: "error title: 7013: the server didn't respond in time") + case 7026: // WALLET_DEPOSIT_GROUP_INSUFFICIENT_BALANCE + String(localized: "Insufficient balance", + comment: "error title: 7026: not enough funds for transaction") +// case 7032: // WALLET_EXCHANGE_UNAVAILABLE +// String(localized: "", +// comment: "error title: 7032: ") + case 7035: // WALLET_TALER_URI_MALFORMED + String(localized: "The talerURI is unknown or invalid", + comment: "error title: 7035: scanned talerURI is not valid") + case 7036: // WALLET_CORE_REQUEST_CANCELLED + String(localized: "User cancelled", + comment: "error title: 7036: the request was cancelled") + case 7037: // WALLET_EXCHANGE_TOS_NOT_ACCEPTED + String(localized: "Terms of Services must be accepted", + comment: "error title: 7037: user didn't accept yet") + case 7041: // WALLET_PEER_PULL_DEBIT_PURSE_GONE + String(localized: "Invoice expired", + comment: "error title: 7041: the payer waited too long") + case 7046, // WALLET_REQUEST_TRANSACTION_STATE_UNSUPPORTED + 7049: // WALLET_MERCHANT_ORDER_NOT_FOUND + String(localized: "Transaction Error", + comment: "error title: 7046,7049: illegal state / tx deleted?") + case 7051: // WALLET_PURCHASE_NOT_FOUND + String(localized: "Purchase missing", + comment: "error title: 7051: refund needs a matching purchase") + case 7054: // WALLET_KYC_LIMIT_EXCEEDED + String(localized: "Limit exceeded", + comment: "error title: 7054: the payment service refused the amount") + case 7055: // WALLET_NO_SUITABLE_EXCHANGE + String(localized: "No suitable payment service", + comment: "error title: 7055: no exchange can serve this request") + case 7057: // WALLET_PEER_CONTRACT_NOT_FOUND + String(localized: "Unknown contract", + comment: "error title: 7057: the exchange does not know this peer-to-peer contract") + case 7064: // WALLET_CONTRACT_TERMS_UNSUPPORTED + String(localized: "Transaction Error", + comment: "error title: 7064: the exchange does not support the contract terms") + default: nil + } + } + init(_ stack: CallStack?, error: Error, devMode: Bool, onDismiss: (() -> Void)? = nil) { let internetError = String(localized: "Network problem") let internetMessage = String(localized: "Please check your internet connection and try again.") @@ -154,35 +192,31 @@ struct ErrorView: View { let deserializationError = String(localized: "Deserialization error") let wrongParameters = String(localized: "Wrong parameters") let unknownError = String(localized: "Unknown error") - let userCancelled = String(localized: "User cancelled") - let transactionError = String(localized: "Transaction Error") switch error { case let walletError as WalletBackendError: switch walletError { case .walletCoreError(let walletBackendResponseError): if let responseError = walletBackendResponseError { + let hint = responseError.errorResponse?.hint ?? responseError.hint // nested one preferred let code = responseError.code - if code == 7002 || code == 7003 || code == 7005 || code == 7032 || code == 7036 || code == 7049 { - self.init(stack, - title: code == 7036 ? userCancelled - : code == 7049 ? transactionError : internetError, - exclam: code != 7036 && code != 7049, - message: responseError.hint ?? internetMessage, + // Limits, quotas and similar conditions are ordinary outcomes the user can act on + if let expectedTitle = Self.titleForExpected(code: code) { + self.init(stack, title: expectedTitle, + exclam: false, // TODO: less alarming icon than exclamation mark? + message: hint ?? internetMessage, requestUrl: responseError.requestUrl, - copyable: false, + copyable: devMode, onDismiss: onDismiss) break } - let hint = responseError.errorResponse?.hint ?? responseError.hint // nested one preferred - // Limits, quotas and similar conditions are ordinary outcomes the user can act on - if let expectedTitle = Self.titleForExpected(code: code) { - self.init(stack, title: expectedTitle, - exclam: false, - message: hint, - requestUrl: responseError.requestUrl, - copyable: devMode, - onDismiss: onDismiss) + if code == 7002 || code == 7003 || code == 7005 || code == 7013 || code == 7032 { + self.init(stack, title: internetError, + exclam: true, + message: hint ?? internetMessage, + requestUrl: responseError.requestUrl, + copyable: devMode, + onDismiss: onDismiss) break } if !devMode, let hint {