diff --git a/ios/Exception/ErrorHandler.swift b/ios/Exception/ErrorHandler.swift index 104a179d..7b1264de 100644 --- a/ios/Exception/ErrorHandler.swift +++ b/ios/Exception/ErrorHandler.swift @@ -3,7 +3,7 @@ import Foundation class ErrorHandler { public static var sharedInstance = ErrorHandler() private var walletExceptionHandler: WalletExceptionHandler? - private var onError: ((_ message: String) -> Void)? + private var onError: ((_ message: String, _ code: String) -> Void)? private init() {} @@ -16,14 +16,14 @@ class ErrorHandler { } } - func setOnError(onError: @escaping (_ message: String) -> Void) { + func setOnError(onError: @escaping (_ message: String. _ code: String) -> Void) { self.onError = onError walletExceptionHandler = WalletExceptionHandler(error: self.onError!) } private func handleUnknownException(error: WalletErrorEnum) { os_log(.error, "Error in OpenID4vBLE: %{public}@", error.description) - self.onError?(error.description) + self.onError?(error.description, error.code) } } diff --git a/ios/Exception/VerifierExceptionHandler.swift b/ios/Exception/VerifierExceptionHandler.swift index e3a9b3b4..1a596e14 100644 --- a/ios/Exception/VerifierExceptionHandler.swift +++ b/ios/Exception/VerifierExceptionHandler.swift @@ -17,4 +17,15 @@ extension VerifierErrorEnum: CustomStringConvertible { return "Minimum 512 MTU is required for VC transfer" } } + + public var code: String { + switch self { + case .corruptedChunkReceived: + return "TVV_TRA_001" + case .tooManyFailureChunks: + return "TVV_TRA_002" + case .unsupportedMTUSizeException: + return "TVV_CON_001" + } + } } diff --git a/ios/Exception/WalletExceptionHandler.swift b/ios/Exception/WalletExceptionHandler.swift index 2521f61f..c8348103 100644 --- a/ios/Exception/WalletExceptionHandler.swift +++ b/ios/Exception/WalletExceptionHandler.swift @@ -2,15 +2,15 @@ import Foundation class WalletExceptionHandler { - private var onError: ((_ message: String) -> Void)? + private var onError: ((_ message: String, _ code: String) -> Void)? - init(error: (@escaping (String) -> Void)) { + init(error: (@escaping (String, String) -> Void)) { self.onError = error } func handle(error: WalletErrorEnum) { os_log(.error, "Error in OpenID4vBLE: %{public}@", error.description) - self.onError?(error.description) + self.onError?(error.description, error.code) } } @@ -28,4 +28,13 @@ extension WalletErrorEnum: CustomStringConvertible { return "failed to write response" } } + + public var code: String { + switch self { + case .invalidMTUSizeError( _): + return "TVW_CON_001" + case .responseTransferFailure: + return "TVW_REP_001" + } + } } diff --git a/ios/Openid4vpBle/Error/ErrorHandler.swift b/ios/Openid4vpBle/Error/ErrorHandler.swift deleted file mode 100644 index b2974ef3..00000000 --- a/ios/Openid4vpBle/Error/ErrorHandler.swift +++ /dev/null @@ -1,22 +0,0 @@ -import Foundation - -class ErrorHandler { - public static var sharedInstance = ErrorHandler() - private var onError: ((_ message: String, _ code: Int) -> Void)?; - - init() {} - - func setOnError(onError: @escaping (_ message: String, _ code: Int) -> Void) { - self.onError = onError - } - - func handle(error: OpenId4vpError) { - os_log(.info, "Error in OpenID4vBLE: %{public}@", error.description) - - if let onError = self.onError { - onError(error.description, error.code) - } else { - os_log(.info, "Failed to send error event to openId4vp module. OnError callback not found.") - } - } -} diff --git a/ios/Openid4vpBle/Error/OpenId4vpError.swift b/ios/Openid4vpBle/Error/OpenId4vpError.swift deleted file mode 100644 index 91fa7c66..00000000 --- a/ios/Openid4vpBle/Error/OpenId4vpError.swift +++ /dev/null @@ -1,32 +0,0 @@ -import Foundation - -enum OpenId4vpError: Error { - case invalidMTUSizeError(mtu: Int) - case responseTransferFailure -} - -extension OpenId4vpError: CustomStringConvertible { - public var description: String { - switch self { - case .invalidMTUSizeError(let mtu): - return "Negotiated MTU: \(mtu) is too low." - case .responseTransferFailure: - return "failed to write response" - } - } - - public var code: String { - switch self { - case .invalidMTUSizeError(let mtu): - return "TVW_CON_001" - case .responseTransferFailure: - return "TVW_REP_001" - } - } -} - -// Error Code format -// (3char)_(3char)_(3char) Eg: TVW-CON-001 -// Stage --> CON(Connection) | KEX(Key Exchange) | ENC(Encryption) | TRA(Transfer) | REP(Report) | DEC(Decryption) -// Component+ROLE --> TVW(Tuvali+Wallet) | TVV(Tuvali+Verifier) | TUV(Tuvali where role is unknown) -// UNK --> If stage is not known diff --git a/ios/Openid4vpBle/EventEmitter.swift b/ios/Openid4vpBle/EventEmitter.swift index 994938c2..1ca13f70 100644 --- a/ios/Openid4vpBle/EventEmitter.swift +++ b/ios/Openid4vpBle/EventEmitter.swift @@ -31,10 +31,10 @@ class EventEmitter { dispatch(name: "EVENT_NEARBY", body: eventData) } - func emitNearbyErrorEvent(message: String, code: Int) { + func emitNearbyErrorEvent(message: String, code: String) { var eventData: [String: String] = [:] eventData["message"] = message - eventData["code"] = String(code) + eventData["code"] = code eventData["type"] = "onError" dispatch(name: "EVENT_NEARBY", body: eventData) diff --git a/ios/Openid4vpBle/Openid4vpBle.swift b/ios/Openid4vpBle/Openid4vpBle.swift index b87365b6..167698f1 100644 --- a/ios/Openid4vpBle/Openid4vpBle.swift +++ b/ios/Openid4vpBle/Openid4vpBle.swift @@ -112,7 +112,7 @@ class Openid4vpBle: RCTEventEmitter { return false } - fileprivate func handleError(_ message: String, _ code: Int) { + fileprivate func handleError(_ message: String, _ code: String) { wallet?.handleDestroyConnection(isSelfDisconnect: false) EventEmitter.sharedInstance.emitNearbyErrorEvent(message: message, code: code) }