Skip to content

Commit f341752

Browse files
committed
refactor: update LAError handling to include companionNotAvailable
1 parent e78f95b commit f341752

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

Sources/LocalAuthenticationProvider/LocalAuthenticationError.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ public enum LocalAuthenticationError: Error {
9191
/// The user tapped the fallback button in the authentication dialog, but no fallback is available for the authentication policy.
9292
case userFallback
9393

94+
/// The authentication failed because the companion device (e.g., Apple Watch) is not available.
95+
case companionNotAvailable
96+
9497
/// An underlying error occurred.
9598
///
9699
/// - Parameter error: The underlying error.

Sources/LocalAuthenticationProvider/LocalAuthenticationProvider.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,16 @@ public final class LocalAuthenticationProvider: LocalAuthenticationProviderProto
199199
logger.error("Biometric sensor data has invalid dimensions: \(localizedDescription)")
200200
return .invalidDimensions
201201
#endif
202-
default:
202+
case .companionNotAvailable:
203+
logger.error("Companion device not available: \(localizedDescription)")
204+
return .companionNotAvailable
205+
206+
@unknown default:
203207
logger.error("Unknown LAError: \(localizedDescription)")
204208
return .error(laError)
209+
// .touchIDLockout (depricated)
210+
// .touchIDNotEnrolled (depricated)
211+
// .touchIDNotAvailable (depricated)
205212
}
206213
}
207214

Tests/LocalAuthenticationProviderTests/LocalAuthProviderLAErrorCasesTests.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,22 @@ final class LocalAuthProviderLAErrorCasesTests: XCTestCase {
165165
} catch {
166166
}
167167
}
168+
169+
@available(iOS 18.0, *)
170+
func testMapToLocalAuthenticationErrorCompanionNotAvailable() async {
171+
let context = MockLAContext(
172+
canEvaluatePolicies: [.deviceOwnerAuthenticationWithBiometrics],
173+
biometryType: .faceID,
174+
evaluatePolicyError: LAError(.companionNotAvailable)
175+
)
176+
let provider = LocalAuthenticationProvider(context: context)
177+
do {
178+
_ = try await provider.authenticate(localizedReason: "Test")
179+
XCTFail("Error must be thrown")
180+
} catch LocalAuthenticationError.companionNotAvailable {
181+
} catch {
182+
}
183+
}
168184
#if os(macOS)
169185
func testMapToLocalAuthenticationErrorBiometryDisconnected() async {
170186
let context = MockLAContext(

0 commit comments

Comments
 (0)