Skip to content

Commit

Permalink
Merge pull request #59 from tw-mosip/remove-duplicate-error-handling-…
Browse files Browse the repository at this point in the history
…on-ios

feat(#71): [Tilak] Remove duplicate error handler from ios
  • Loading branch information
PoojaBabusing authored May 17, 2023
2 parents e2f829d + 4a902e3 commit 50fe60f
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 63 deletions.
6 changes: 3 additions & 3 deletions ios/Exception/ErrorHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}

Expand All @@ -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)
}
}

Expand Down
11 changes: 11 additions & 0 deletions ios/Exception/VerifierExceptionHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
15 changes: 12 additions & 3 deletions ios/Exception/WalletExceptionHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand All @@ -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"
}
}
}
22 changes: 0 additions & 22 deletions ios/Openid4vpBle/Error/ErrorHandler.swift

This file was deleted.

32 changes: 0 additions & 32 deletions ios/Openid4vpBle/Error/OpenId4vpError.swift

This file was deleted.

4 changes: 2 additions & 2 deletions ios/Openid4vpBle/EventEmitter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion ios/Openid4vpBle/Openid4vpBle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 50fe60f

Please sign in to comment.