Skip to content

Commit 7f845f4

Browse files
authored
[AuthErrorCode] should conform to Swift.Error (#13434)
1 parent f0a6472 commit 7f845f4

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

FirebaseAuth/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# 11.1.0
2+
- [fixed] Fixed `Swift.error` conformance for `AuthErrorCode`. (#13430)
23
- [added] Added custom provider support to `AuthProviderID`. Note that this change will be breaking
34
to any code that implemented an exhaustive `switch` on `AuthProviderID` in 11.0.0 - the `switch`
45
will need expansion. (#13429)

FirebaseAuth/Sources/Swift/Utilities/AuthErrors.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ import Foundation
4848
}
4949

5050
/// Error codes used by Firebase Auth.
51-
@objc(FIRAuthErrorCode) public enum AuthErrorCode: Int {
51+
@objc(FIRAuthErrorCode) public enum AuthErrorCode: Int, Error {
5252
/// Indicates a validation error with the custom token.
5353
case invalidCustomToken = 17000
5454

@@ -537,6 +537,12 @@ import Foundation
537537
}
538538
}
539539

540+
/// The error code. It's redundant but implemented for compatibility with the Objective-C
541+
/// implementation.
542+
public var code: Self {
543+
return self
544+
}
545+
540546
var errorCodeString: String {
541547
switch self {
542548
case .invalidCustomToken:

FirebaseAuth/Tests/Unit/SwiftAPI.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,4 +725,22 @@ class AuthAPI_hOnlyTests: XCTestCase {
725725
return 9
726726
}
727727
}
728+
729+
func regression13430(error: NSError) -> Int {
730+
if let firebaseError = error as? AuthErrorCode, firebaseError == .networkError {
731+
return 1
732+
}
733+
734+
if let firebaseError = error as? AuthErrorCode, firebaseError.code == .invalidPhoneNumber {
735+
switch firebaseError.localizedDescription {
736+
case "TOO_SHORT":
737+
return 1
738+
case "TOO_LONG":
739+
return 1
740+
default:
741+
return 1
742+
}
743+
}
744+
return 2
745+
}
728746
}

0 commit comments

Comments
 (0)