Skip to content

Commit

Permalink
Auth V2 / LegacyTokenStoring error handling (#1202)
Browse files Browse the repository at this point in the history
Task/Issue URL:
https://app.asana.com/0/72649045549333/1209252725802998/f

**Description**:

Error handling added to the AuthV2 LegacyTokenStoring implementation
  • Loading branch information
federicocappelli authored Feb 4, 2025
1 parent 4376de0 commit 05cfe11
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ import Common
public final class SubscriptionTokenKeychainStorage: SubscriptionTokenStoring {

private let keychainType: KeychainType
let errorHandler: ((AccountKeychainAccessType, AccountKeychainAccessError) -> Void)?

public init(keychainType: KeychainType = .dataProtection(.unspecified)) {
public init(keychainType: KeychainType = .dataProtection(.unspecified),
errorHandler: ((AccountKeychainAccessType, AccountKeychainAccessError) -> Void)? = nil) {
self.keychainType = keychainType
self.errorHandler = errorHandler
}

public func getAccessToken() throws -> String? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import Foundation
import Networking
import os.log

extension SubscriptionTokenKeychainStorage: LegacyAuthTokenStoring {

Expand All @@ -26,7 +27,12 @@ extension SubscriptionTokenKeychainStorage: LegacyAuthTokenStoring {
do {
return try getAccessToken()
} catch {
assertionFailure("Failed to retrieve auth token: \(error)")
if let error = error as? AccountKeychainAccessError {
errorHandler?(AccountKeychainAccessType.getAuthToken, error)
} else {
assertionFailure("Unexpected error: \(error)")
Logger.subscriptionKeychain.fault("Unexpected error: \(error, privacy: .public)")
}
}
return nil
}
Expand All @@ -38,7 +44,13 @@ extension SubscriptionTokenKeychainStorage: LegacyAuthTokenStoring {
}
try store(accessToken: newValue)
} catch {
assertionFailure("Failed set token: \(error)")
Logger.subscriptionKeychain.fault("Failed to set TokenContainer: \(error, privacy: .public)")
if let error = error as? AccountKeychainAccessError {
errorHandler?(AccountKeychainAccessType.storeAuthToken, error)
} else {
assertionFailure("Unexpected error: \(error)")
Logger.subscriptionKeychain.fault("Unexpected error: \(error, privacy: .public)")
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public final class SubscriptionTokenKeychainStorageV2: AuthTokenStoring {
errorHandler(AccountKeychainAccessType.getAuthToken, error)
} else {
assertionFailure("Unexpected error: \(error)")
Logger.OAuth.fault("Unexpected error: \(error, privacy: .public)")

Logger.subscriptionKeychain.fault("Unexpected error: \(error, privacy: .public)")
}

return nil
Expand All @@ -70,7 +71,7 @@ public final class SubscriptionTokenKeychainStorageV2: AuthTokenStoring {
errorHandler(AccountKeychainAccessType.storeAuthToken, error)
} else {
assertionFailure("Unexpected error: \(error)")
Logger.OAuth.fault("Unexpected error: \(error, privacy: .public)")
Logger.subscriptionKeychain.fault("Unexpected error: \(error, privacy: .public)")
}
}
}
Expand Down

0 comments on commit 05cfe11

Please sign in to comment.