Skip to content

Commit

Permalink
Log error and fix invalid method reference
Browse files Browse the repository at this point in the history
  • Loading branch information
NachoSoto committed May 19, 2023
1 parent 89db351 commit ffb1bcf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
14 changes: 10 additions & 4 deletions Sources/OfflineEntitlements/PurchasedProductsFetcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,17 @@ class PurchasedProductsFetcher: PurchasedProductsFetcherType {
}
}

if result.isEmpty, let error = syncError {
// Only throw errors when syncing with the store if there were no entitlements found
throw error
if let error = syncError {
if result.isEmpty {
// Only throw errors when syncing with the store if there were no entitlements found
throw error
} else {
Logger.appleError(error.localizedDescription)

// If there are any entitlements, ignore the error.
return result
}
} else {
// If there are any entitlements, ignore the error.
return result
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class BasePurchasedProductsFetcherTests: StoreKitConfigTestCase {

self.sandboxDetector = MockSandboxEnvironmentDetector(isSandbox: .random())
self.fetcher = PurchasedProductsFetcher(
appStoreSync: self.syncAppStore,
appStoreSync: { try await self.syncAppStore() },
sandboxDetector: self.sandboxDetector
)
}
Expand Down Expand Up @@ -101,8 +101,8 @@ class FailingSyncPurchasedProductsFetcherTests: BasePurchasedProductsFetcherTest

func testThrowsIfNoPurchasedProducts() async throws {
do {
_ = try await self.fetcher.fetchPurchasedProducts()
fail("Expected error")
let result = try await self.fetcher.fetchPurchasedProducts()
fail("Expected error. Found \(result.count) products")
} catch let error {
expect(error).to(matchError(Self.error))
}
Expand Down

0 comments on commit ffb1bcf

Please sign in to comment.