taler-ios

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

WalletBackendError.swift (2373B)


      1 /*
      2  * This file is part of GNU Taler, ©2022-26 Taler Systems S.A.
      3  * See LICENSE.md
      4  */
      5 /**
      6  * @author Marc Stibane
      7  * @author Iván Ávalos
      8  */
      9 import Foundation
     10 import taler_swift
     11 
     12 /// Errors for `WalletBackend`.
     13 enum WalletBackendError: Error {
     14     /// An error that prevented the wallet from being initialized occurred.
     15     case initializationError
     16     case serializationError
     17     case deserializationError
     18     case wrongParameters
     19     case walletCoreError(TalerErrorDetail?)
     20 }
     21 
     22 /// Information supplied by the backend describing an error.
     23 //struct WalletBackendResponseError: Codable {
     24 //    /// Numeric error code defined below (-1..-4)
     25 //    var code: Int
     26 //    // all other fields are optional:
     27 //    var when: Timestamp?
     28 //    /// English description of the error code.
     29 //    var hint: String?
     30 //    /// English diagnostic message that can give details for the instance of the error.
     31 //    var message: String?
     32 //
     33 //    var requestUrl: String?
     34 ////    var httpStatusCode: Int?
     35 ////    var requestMethod: String?
     36 //
     37 //    var errorResponse: TalerErrorDetail?
     38 //
     39 //    var insufficientBalanceDetails: PaymentInsufficientBalanceDetails? = nil
     40 //}
     41 
     42 struct WalletBackendAbortReason: Codable {
     43     /// Numeric error code defined below (-1..-4)
     44     var code: Int
     45     // all other fields are optional:
     46     var when: Timestamp?
     47     /// English description of the error code.
     48     var hint: String?
     49     /// English diagnostic message that can give details for the instance of the error.
     50     var message: String?
     51 
     52     var exchangeResponse: TalerErrorDetail?
     53 }
     54 
     55 extension WalletCore {
     56     static func serializeRequestError() -> TalerErrorDetail {
     57         return TalerErrorDetail(code: -1, when: Timestamp.now(),
     58                                 hint: "Could not serialize request.")
     59     }
     60     
     61     static func parseResponseError() -> TalerErrorDetail {
     62         return TalerErrorDetail(code: -2, when: Timestamp.now(),
     63                                 hint: "Could not parse response.")
     64     }
     65     
     66     static func parseFailureError() -> TalerErrorDetail {
     67         return TalerErrorDetail(code: -3, when: Timestamp.now(),
     68                                 hint: "Could not parse error detail.")
     69     }
     70 
     71     static func walletError() -> TalerErrorDetail {
     72         return TalerErrorDetail(code: -4, when: Timestamp.now(),
     73                                 hint: "Error detail.")
     74     }
     75 }