Skip to content

Commit 3dfab48

Browse files
Merge pull request #17 from Web3Auth/swift-better-error-handling
Swift better error handling
2 parents a3440d1 + e1baafe commit 3dfab48

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

ios/Classes/SingleFactorAuthFlutterPlugin.swift

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class SingleFactorAuthFlutterPlugin: NSObject, FlutterPlugin {
4646
case "init":
4747
let args = call.arguments as? String
4848
guard let data = args?.data(using: .utf8) else {
49-
return result(throwKeyNotGeneratedError())
49+
return result(throwParamMissingError(param: args))
5050
}
5151

5252
let params = try self.decoder.decode(InitParams.self, from: data)
@@ -74,13 +74,17 @@ public class SingleFactorAuthFlutterPlugin: NSObject, FlutterPlugin {
7474
let resultJson = String(decoding: resultData, as: UTF8.self)
7575
return result(resultJson)
7676
} catch {
77-
result(throwKeyNotGeneratedError())
77+
result(FlutterError(
78+
code: (error as NSError).domain,
79+
message: error.localizedDescription,
80+
details: String(describing: error)
81+
))
7882
}
7983

8084
case "connect":
8185
let args = call.arguments as? String
8286
guard let data = args?.data(using: .utf8) else {
83-
return result(throwKeyNotGeneratedError())
87+
return result(throwParamMissingError(param: args))
8488
}
8589

8690
let params = try self.decoder.decode(getTorusKeyParams.self, from: data)
@@ -116,7 +120,11 @@ public class SingleFactorAuthFlutterPlugin: NSObject, FlutterPlugin {
116120
let resultJson = String(decoding: resultData, as: UTF8.self)
117121
return result(resultJson)
118122
} catch {
119-
result(throwKeyNotGeneratedError())
123+
result(FlutterError(
124+
code: (error as NSError).domain,
125+
message: error.localizedDescription,
126+
details: String(describing: error)
127+
))
120128
}
121129
break
122130

@@ -129,7 +137,11 @@ public class SingleFactorAuthFlutterPlugin: NSObject, FlutterPlugin {
129137
return result(isSessionExists)
130138
}
131139
} catch {
132-
result(throwKeyNotGeneratedError())
140+
result(FlutterError(
141+
code: (error as NSError).domain,
142+
message: error.localizedDescription,
143+
details: String(describing: error)
144+
))
133145
}
134146
break
135147

@@ -139,13 +151,7 @@ public class SingleFactorAuthFlutterPlugin: NSObject, FlutterPlugin {
139151
}
140152
}
141153

142-
public func throwKeyNotGeneratedError() -> FlutterError {
143-
return FlutterError(
144-
code: "key_not_generated", message: "Key not generated", details: nil
145-
)
146-
}
147-
148-
public func throwParamMissingError(param: String) -> FlutterError {
154+
public func throwParamMissingError(param: String?) -> FlutterError {
149155
return FlutterError(
150156
code: "missing_param", message: param, details: nil
151157
)

0 commit comments

Comments
 (0)