ErrorUtils.purchasesError(withUntypedError:): handle PublicErrors#2165
Conversation
See RevenueCat/purchases-hybrid-common#278. A valid error ended up as: > failed: caught error: "Unknown error." This change ensures that calling this method with an `NSError` does not return `ErrorCode.unknownError`, and instead we extract the correct error.
| ) -> PurchasesError { | ||
| func handlePublicError(_ error: PublicError) -> PurchasesError { | ||
| if let errorCode = ErrorCode(rawValue: error.code) { | ||
| return .init(error: errorCode, userInfo: error.userInfo) |
There was a problem hiding this comment.
I might be wrong but when we convert this in purchases-hybrid-common https://github.com/RevenueCat/purchases-hybrid-common/blob/main/ios/PurchasesHybridCommon/PurchasesHybridCommon/ErrorContainer.swift#L23 the nsError.code code will be the backend's returned error code?
There was a problem hiding this comment.
This isn’t changing the code though.
This method is used because Swift doesn’t have typed throws, so we need a way to convert from Error to a typed PurchasesError. But this method won’t change the error at all. You can see that in the tests.
| return backendError.asPurchasesError | ||
| case let networkError as NetworkError: | ||
| return networkError.asPurchasesError | ||
| case let error as PublicError where error.domain == ErrorCode.errorDomain: |
There was a problem hiding this comment.
This might be a stupid question but where do we define our errorDomain? I couldn't find it 😆
There was a problem hiding this comment.
Not a stupid question 😅 It’s Swift magic for Swift.Error conformances.
See also #1275.
**This is an automatic release.** ### Bugfixes * `ErrorUtils.purchasesError(withUntypedError:)`: handle `PublicError`s (#2165) via NachoSoto (@NachoSoto) * Fixed race condition finishing `SK1` transactions (#2148) via NachoSoto (@NachoSoto) * `IntroEligibilityStatus`: added `CustomStringConvertible` implementation (#2182) via NachoSoto (@NachoSoto) * `BundleSandboxEnvironmentDetector`: fixed logic for `macOS` (#2176) via NachoSoto (@NachoSoto) * Fixed `AttributionFetcher.adServicesToken` hanging when called in simulator (#2157) via NachoSoto (@NachoSoto) ### Other Changes * `Purchase Tester`: added ability to purchase products directly with `StoreKit` (#2172) via NachoSoto (@NachoSoto) * `DNSChecker`: simplified `NetworkError` initialization (#2166) via NachoSoto (@NachoSoto) * `Purchases` initialization: refactor to avoid multiple concurrent instances in memory (#2180) via NachoSoto (@NachoSoto) * `Purchase Tester`: added button to clear messages on logger view (#2179) via NachoSoto (@NachoSoto) * `NetworkOperation`: added assertion to ensure that subclasses call completion (#2138) via NachoSoto (@NachoSoto) * `CacheableNetworkOperation`: avoid unnecessarily creating operations for cache hits (#2135) via NachoSoto (@NachoSoto) * `PurchaseTester`: fixed `macOS` support (#2175) via NachoSoto (@NachoSoto) * `IntroEligibilityCalculator`: added log including `AppleReceipt` (#2181) via NachoSoto (@NachoSoto) * `Purchase Tester`: fixed scene manifest (#2170) via NachoSoto (@NachoSoto) * `HTTPClientTests`: refactored to use `waitUntil` (#2168) via NachoSoto (@NachoSoto) * `Integration Tests`: split up tests in smaller files (#2158) via NachoSoto (@NachoSoto) * `StoreKitRequestFetcher`: removed unnecessary dispatch (#2152) via NachoSoto (@NachoSoto) * `Purchase Tester`: added companion `watchOS` app (#2140) via NachoSoto (@NachoSoto) * `StoreKit1Wrapper`: added warning if receiving too many updated transactions (#2117) via NachoSoto (@NachoSoto) * `StoreKitTestHelpers`: cleaned up unnecessary log (#2177) via NachoSoto (@NachoSoto) * `TrialOrIntroPriceEligibilityCheckerSK1Tests`: use `waitUntilValue` (#2173) via NachoSoto (@NachoSoto) * `DNSChecker`: added log with resolved host (#2167) via NachoSoto (@NachoSoto) * `MagicWeatherSwiftUI`: updated `README` to point to workspace (#2142) via NachoSoto (@NachoSoto) * `Purchase Tester`: fixed `.storekit` config file reference (#2171) via NachoSoto (@NachoSoto) * `Purchase Tester`: fixed error alerts (#2169) via NachoSoto (@NachoSoto) * `CI`: don't make releases until `release-checks` pass (#2162) via NachoSoto (@NachoSoto) * `Fastfile`: changed `match` to `readonly` (#2161) via NachoSoto (@NachoSoto)
See RevenueCat/purchases-hybrid-common#278.
A valid error ended up as:
This change ensures that calling this method with an
NSErrordoes not returnErrorCode.unknownError, and instead we extract the correct error.