WalletBackendError.swift (2128B)
1 /* 2 * This file is part of GNU Taler, ©2022-25 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 walletCoreError(WalletBackendResponseError?) 19 } 20 21 /// Information supplied by the backend describing an error. 22 struct WalletBackendResponseError: Codable { 23 /// Numeric error code defined below (-1..-4) 24 var code: Int 25 // all other fields are optional: 26 var when: Timestamp? 27 /// English description of the error code. 28 var hint: String? 29 /// English diagnostic message that can give details for the instance of the error. 30 var message: String? 31 32 // var requestUrl: String? 33 // var httpStatusCode: Int? 34 // var requestMethod: String? 35 36 var errorResponse: TalerErrorDetail? 37 38 var insufficientBalanceDetails: PaymentInsufficientBalanceDetails? = nil 39 } 40 41 extension WalletCore { 42 static func serializeRequestError() -> WalletBackendResponseError { 43 return WalletBackendResponseError(code: -1, when: Timestamp.now(), 44 hint: "Could not serialize request.", message: EMPTYSTRING) 45 } 46 47 static func parseResponseError() -> WalletBackendResponseError { 48 return WalletBackendResponseError(code: -2, when: Timestamp.now(), 49 hint: "Could not parse response.", message: EMPTYSTRING) 50 } 51 52 static func parseFailureError() -> WalletBackendResponseError { 53 return WalletBackendResponseError(code: -3, when: Timestamp.now(), 54 hint: "Could not parse error detail.", message: EMPTYSTRING) 55 } 56 57 static func walletError() -> WalletBackendResponseError { 58 return WalletBackendResponseError(code: -4, when: Timestamp.now(), 59 hint: "Error detail.", message: EMPTYSTRING) 60 } 61 }