diff --git a/TalerWallet1/Views/Main/ErrorView.swift b/TalerWallet1/Views/Main/ErrorView.swift index af392083..8b8e4d21 100644 --- a/TalerWallet1/Views/Main/ErrorView.swift +++ b/TalerWallet1/Views/Main/ErrorView.swift @@ -102,6 +102,31 @@ enum ErrorData { } struct ErrorView: View { + + /// Title for wallet-core errors that are expected outcomes rather than + /// faults, keyed by `TalerErrorCode`. + /// + /// Returning nil means "no better title than the generic one", so an + /// unrecognised code still falls through to the existing behaviour. + static func titleForExpected(code: Int) -> String? { + switch code { + case 7054: // WALLET_KYC_LIMIT_EXCEEDED + return String(localized: "Limit exceeded", + comment: "error title: the payment service refused the amount") + case 7055: // WALLET_NO_SUITABLE_EXCHANGE + return String(localized: "No suitable payment service", + comment: "error title: no exchange can serve this request") + case 7064: // WALLET_CONTRACT_TERMS_UNSUPPORTED + return String(localized: "Transaction Error") + case 7000, // WALLET_EXCHANGE_PROTOCOL_VERSION_INCOMPATIBLE + 7017: // WALLET_BANK_INTEGRATION_PROTOCOL_VERSION_INCOMPATIBLE + return String(localized: "Incompatible version", + comment: "error title: the server speaks a protocol this app does not") + default: + return nil + } + } + let stack: CallStack? var title: String var exclam: Bool @@ -152,6 +177,23 @@ struct ErrorView: View { break } let hint = responseError.errorResponse?.hint ?? responseError.hint // nested one preferred + // Not every wallet-core error is an internal fault. + // Limits, quotas and similar conditions are ordinary + // outcomes the user can act on, and titling them + // "Internal core error" tells them they hit a bug when + // they did not. Give those a title that matches what + // happened; anything genuinely unexpected keeps the + // internal-error title. + let expectedTitle = ErrorView.titleForExpected(code: code) + if let expectedTitle { + self.init(stack, title: expectedTitle, + exclam: false, + message: hint, + requestUrl: responseError.requestUrl, + copyable: devMode, + onDismiss: onDismiss) + break + } if !devMode, let hint { // prefer hint for regular users self.init(stack, title: walletCoreError, message: hint, copyable: true, onDismiss: onDismiss)