WalletBackendError.swift (2348B)
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(TalerErrorDetail?) 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 struct WalletBackendAbortReason: Codable { 42 /// Numeric error code defined below (-1..-4) 43 var code: Int 44 // all other fields are optional: 45 var when: Timestamp? 46 /// English description of the error code. 47 var hint: String? 48 /// English diagnostic message that can give details for the instance of the error. 49 var message: String? 50 51 var exchangeResponse: TalerErrorDetail? 52 } 53 54 extension WalletCore { 55 static func serializeRequestError() -> TalerErrorDetail { 56 return TalerErrorDetail(code: -1, when: Timestamp.now(), 57 hint: "Could not serialize request.") 58 } 59 60 static func parseResponseError() -> TalerErrorDetail { 61 return TalerErrorDetail(code: -2, when: Timestamp.now(), 62 hint: "Could not parse response.") 63 } 64 65 static func parseFailureError() -> TalerErrorDetail { 66 return TalerErrorDetail(code: -3, when: Timestamp.now(), 67 hint: "Could not parse error detail.") 68 } 69 70 static func walletError() -> TalerErrorDetail { 71 return TalerErrorDetail(code: -4, when: Timestamp.now(), 72 hint: "Error detail.") 73 } 74 }