taler-ios

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

commit 4c12077c7eb6db009feb8682614fdd1708846d8a
parent 4aafe04d2285399758cb1c344ed0a39e570e3ef8
Author: Marc Stibane <marc@taler.net>
Date:   Mon, 15 Apr 2024 13:22:26 +0200

errorResponse

Diffstat:
MTalerWallet1/Backend/WalletBackendError.swift | 37++++++++++++++++++++++++++++---------
MTalerWallet1/Views/Sheets/ErrorSheet.swift | 3++-
2 files changed, 30 insertions(+), 10 deletions(-)

diff --git a/TalerWallet1/Backend/WalletBackendError.swift b/TalerWallet1/Backend/WalletBackendError.swift @@ -7,6 +7,7 @@ * @author Iván Ávalos */ import Foundation +import taler_swift /// Errors for `WalletBackend`. enum WalletBackendError: Error { @@ -17,35 +18,53 @@ enum WalletBackendError: Error { case walletCoreError(WalletBackendResponseError?) } +struct ErrorResponse: Codable { + var code: Int + /// English description of the error code. + var hint: String + + /// Error details, type depends on `talerErrorCode`. + var detail: String? = nil +} + /// Information supplied by the backend describing an error. struct WalletBackendResponseError: Codable { /// Numeric error code defined defined in the GANA gnu-taler-error-codes registry. var code: Int - + + var when: Timestamp + /// English description of the error code. var hint: String - + + var requestUrl: String? = nil + + var httpStatusCode: Int? = nil + + var errorResponse: ErrorResponse? = nil + /// English diagnostic message that can give details for the instance of the error. var message: String? = nil - - /// Error details, type depends on `talerErrorCode`. - var details: Data? = nil } extension WalletCore { static func serializeRequestError() -> WalletBackendResponseError { - return WalletBackendResponseError(code: -1, hint: "Could not serialize request.", message: "") + return WalletBackendResponseError(code: -1, when: Timestamp.now(), + hint: "Could not serialize request.", message: "") } static func parseResponseError() -> WalletBackendResponseError { - return WalletBackendResponseError(code: -2, hint: "Could not parse response.", message: "") + return WalletBackendResponseError(code: -2, when: Timestamp.now(), + hint: "Could not parse response.", message: "") } static func parseFailureError() -> WalletBackendResponseError { - return WalletBackendResponseError(code: -3, hint: "Could not parse error detail.", message: "") + return WalletBackendResponseError(code: -3, when: Timestamp.now(), + hint: "Could not parse error detail.", message: "") } static func walletError() -> WalletBackendResponseError { - return WalletBackendResponseError(code: -4, hint: "Error detail.", message: "") + return WalletBackendResponseError(code: -4, when: Timestamp.now(), + hint: "Error detail.", message: "") } } diff --git a/TalerWallet1/Views/Sheets/ErrorSheet.swift b/TalerWallet1/Views/Sheets/ErrorSheet.swift @@ -6,6 +6,7 @@ * @author Iván Ávalos */ import SwiftUI +import taler_swift enum ErrorData { case message(title: String, message: String) @@ -119,7 +120,7 @@ struct ErrorSheet: View { struct ErrorSheet_Previews: PreviewProvider { static let error = WalletBackendError.walletCoreError(WalletBackendResponseError( - code: 7025, + code: 7025, when: Timestamp.now(), hint: "A KYC step is required before withdrawal can proceed", message: "A KYC step is required before withdrawal can proceed"))