Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AuthErrorCode] should conform to Swift.Error #13434

Merged
merged 2 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions FirebaseAuth/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# 11.1.0
- [fixed] Fixed `Swift.error` conformance for `AuthErrorCode`. (#13430)
- [added] Added custom provider support to `AuthProviderID`. Note that this change will be breaking
to any code that implemented an exhaustive `switch` on `AuthProviderID` in 11.0.0 - the `switch`
will need expansion. (#13429)
Expand Down
8 changes: 7 additions & 1 deletion FirebaseAuth/Sources/Swift/Utilities/AuthErrors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import Foundation
}

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

Expand Down Expand Up @@ -537,6 +537,12 @@ import Foundation
}
}

/// The error code. It's redundant but implemented for compatibility with the Objective-C
/// implementation.
public var code: Self {
return self
}

var errorCodeString: String {
switch self {
case .invalidCustomToken:
Expand Down
18 changes: 18 additions & 0 deletions FirebaseAuth/Tests/Unit/SwiftAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -725,4 +725,22 @@ class AuthAPI_hOnlyTests: XCTestCase {
return 9
}
}

func regression13430(error: NSError) -> Int {
if let firebaseError = error as? AuthErrorCode, firebaseError == .networkError {
return 1
}

if let firebaseError = error as? AuthErrorCode, firebaseError.code == .invalidPhoneNumber {
switch firebaseError.localizedDescription {
case "TOO_SHORT":
return 1
case "TOO_LONG":
return 1
default:
return 1
}
}
return 2
}
}
Loading