Skip to content

Commit

Permalink
use do catch, more details in error log
Browse files Browse the repository at this point in the history
  • Loading branch information
Maddie Beyl committed Apr 28, 2022
1 parent a11742a commit 6a7697b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
8 changes: 5 additions & 3 deletions Sources/Attribution/AttributionFetcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,12 @@ class AttributionFetcher {
@available(iOS 14.3, macOS 11.1, macCatalyst 14.3, *)
var adServicesToken: String? {
#if canImport(AdServices)
if let attributionToken = try? AAAttribution.attributionToken() {
do {
let attributionToken = try AAAttribution.attributionToken()

This comment has been minimized.

Copy link
@NachoSoto

NachoSoto Apr 28, 2022

Contributor

Nit: this seems unnecessary, maybe just return try AAAttribution.attributionToken()?

return attributionToken
} else {
Logger.warn(Strings.attribution.adservices_token_fetch_failed)
} catch {
let message = Strings.attribution.adservices_token_fetch_failed(error: error)
Logger.appleWarning(message)
return nil
}
#else
Expand Down
6 changes: 3 additions & 3 deletions Sources/Logging/Strings/AttributionStrings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ enum AttributionStrings {
case attribute_set_locally(attribute: String)
case missing_advertiser_identifiers
case adservices_not_supported
case adservices_token_fetch_failed
case adservices_token_fetch_failed(error: Error?)

This comment has been minimized.

Copy link
@NachoSoto

NachoSoto Apr 28, 2022

Contributor

Does this have to be optional?

This comment has been minimized.

Copy link
@NachoSoto

NachoSoto Apr 28, 2022

Contributor

@beylmk I meant the error in adservices_token_fetch_failed. Weak linking the framework looks good!


}

Expand Down Expand Up @@ -120,8 +120,8 @@ extension AttributionStrings: CustomStringConvertible {
return "Tried to fetch AdServices attribution token on device without " +
"AdServices support."

case .adservices_token_fetch_failed:
return "Error fetching AdServices attribution token."
case .adservices_token_fetch_failed(let error):
return "Fetching AdServices attribution token failed with error: \(error?.localizedDescription ?? "")"
}
}

Expand Down

0 comments on commit 6a7697b

Please sign in to comment.