Skip to content

Commit 8c4c663

Browse files
authored
Merge pull request #364 from firebase/swift_error_hacking
Update FUICustomAuthUIDelegate.swift for swift error hacking
2 parents 5cd0d8b + 8537d10 commit 8c4c663

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

samples/swift/FirebaseUI-demo-swift/Samples/Auth/FUICustomAuthUIDelegate.swift

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,15 @@ import FirebaseAuth
2121
class FUICustomAuthDelegate: NSObject, FUIAuthDelegate {
2222

2323
func authUI(_ authUI: FUIAuth, didSignInWith user: User?, error: Error?) {
24-
guard let authError = error else { return }
25-
26-
let errorCode = UInt((authError as NSError).code)
27-
28-
switch errorCode {
29-
case FUIAuthErrorCode.userCancelledSignIn.rawValue:
30-
print("User cancelled sign-in");
31-
break
32-
default:
33-
let detailedError = (authError as NSError).userInfo[NSUnderlyingErrorKey] ?? authError
34-
print("Login error: \((detailedError as! NSError).localizedDescription)");
35-
}
24+
switch error {
25+
case .some(let error as NSError) where UInt(error.code) == FUIAuthErrorCode.userCancelledSignIn.rawValue:
26+
print("User cancelled sign-in")
27+
case .some(let error as NSError) where error.userInfo[NSUnderlyingErrorKey] != nil:
28+
print("Login error: \(error.userInfo[NSUnderlyingErrorKey]!)")
29+
case .some(let error):
30+
print("Login error: \(error.localizedDescription)")
31+
case .none:
32+
return
3633
}
3734

3835
func authPickerViewController(forAuthUI authUI: FUIAuth) -> FUIAuthPickerViewController {

0 commit comments

Comments
 (0)