Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions ios/Classes/SingleFactorAuthFlutterPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class SingleFactorAuthFlutterPlugin: NSObject, FlutterPlugin {
case "init":
let args = call.arguments as? String
guard let data = args?.data(using: .utf8) else {
return result(throwKeyNotGeneratedError())
return result(throwParamMissingError(param: args))
}

let params = try self.decoder.decode(InitParams.self, from: data)
Expand Down Expand Up @@ -74,13 +74,17 @@ public class SingleFactorAuthFlutterPlugin: NSObject, FlutterPlugin {
let resultJson = String(decoding: resultData, as: UTF8.self)
return result(resultJson)
} catch {
result(throwKeyNotGeneratedError())
result(FlutterError(
code: (error as NSError).domain,
message: error.localizedDescription,
details: String(describing: error)
))
}

case "connect":
let args = call.arguments as? String
guard let data = args?.data(using: .utf8) else {
return result(throwKeyNotGeneratedError())
return result(throwParamMissingError(param: args))
}

let params = try self.decoder.decode(getTorusKeyParams.self, from: data)
Expand Down Expand Up @@ -116,7 +120,11 @@ public class SingleFactorAuthFlutterPlugin: NSObject, FlutterPlugin {
let resultJson = String(decoding: resultData, as: UTF8.self)
return result(resultJson)
} catch {
result(throwKeyNotGeneratedError())
result(FlutterError(
code: (error as NSError).domain,
message: error.localizedDescription,
details: String(describing: error)
))
}
break

Expand All @@ -129,7 +137,11 @@ public class SingleFactorAuthFlutterPlugin: NSObject, FlutterPlugin {
return result(isSessionExists)
}
} catch {
result(throwKeyNotGeneratedError())
result(FlutterError(
code: (error as NSError).domain,
message: error.localizedDescription,
details: String(describing: error)
))
}
break

Expand All @@ -139,13 +151,7 @@ public class SingleFactorAuthFlutterPlugin: NSObject, FlutterPlugin {
}
}

public func throwKeyNotGeneratedError() -> FlutterError {
return FlutterError(
code: "key_not_generated", message: "Key not generated", details: nil
)
}

public func throwParamMissingError(param: String) -> FlutterError {
public func throwParamMissingError(param: String?) -> FlutterError {
return FlutterError(
code: "missing_param", message: param, details: nil
)
Expand Down