Skip to content

Commit

Permalink
Purchases.beginRefundRequest: ensured errors are PublicError (#1913)
Browse files Browse the repository at this point in the history
This was missed in #1879. Without this, we might have been forwarding
some private errors instead of ensuring that we only sent `CodeError`s
  • Loading branch information
NachoSoto authored Sep 21, 2022
1 parent 849efda commit 12cf786
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
1 change: 0 additions & 1 deletion Sources/Error Handling/ErrorUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,6 @@ enum ErrorUtils {
* If the error is already a `PurchasesError`, this simply returns the same value,
* otherwise it wraps it into a ``ErrorCode/unknownError``.
*/
@available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *)
static func purchasesError(
withUntypedError error: Error,
fileName: String = #fileID, functionName: String = #function, line: UInt = #line
Expand Down
10 changes: 5 additions & 5 deletions Sources/Misc/Purchases+nonasync.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public extension Purchases {
@available(tvOS, unavailable)
func beginRefundRequest(
forProduct productID: String,
completion: @escaping (Result<RefundRequestStatus, Error>) -> Void
completion: @escaping (Result<RefundRequestStatus, PublicError>) -> Void
) {
call(with: completion) {
try await self.beginRefundRequest(forProduct: productID)
Expand All @@ -57,7 +57,7 @@ public extension Purchases {
@available(tvOS, unavailable)
func beginRefundRequest(
forEntitlement entitlementID: String,
completion: @escaping (Result<RefundRequestStatus, Error>) -> Void
completion: @escaping (Result<RefundRequestStatus, PublicError>) -> Void
) {
call(with: completion) {
try await self.beginRefundRequest(forEntitlement: entitlementID)
Expand All @@ -82,7 +82,7 @@ public extension Purchases {
@available(watchOS, unavailable)
@available(tvOS, unavailable)
func beginRefundRequestForActiveEntitlement(
completion: @escaping (Result<RefundRequestStatus, Error>) -> Void
completion: @escaping (Result<RefundRequestStatus, PublicError>) -> Void
) {
call(with: completion) {
try await self.beginRefundRequestForActiveEntitlement()
Expand All @@ -96,14 +96,14 @@ public extension Purchases {
/// Invokes an `async throws` method and calls `completion` with the result.
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.2, *)
private func call<T>(
with completion: @escaping (Result<T, Error>) -> Void,
with completion: @escaping (Result<T, PublicError>) -> Void,
asyncMethod method: @escaping () async throws -> T
) {
_ = Task {
do {
completion(.success(try await method()))
} catch {
completion(.failure(error))
completion(.failure(ErrorUtils.purchasesError(withUntypedError: error).asPublicError))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,9 @@ private func checkAsyncMethods(purchases: Purchases) async {

func checkNonAsyncMethods(_ purchases: Purchases) {
#if os(iOS)
purchases.beginRefundRequest(forProduct: "") { (_: Result<RefundRequestStatus, Error>) in }
purchases.beginRefundRequest(forEntitlement: "") { (_: Result<RefundRequestStatus, Error>) in }
purchases.beginRefundRequestForActiveEntitlement { (_: Result<RefundRequestStatus, Error>) in }
purchases.beginRefundRequest(forProduct: "") { (_: Result<RefundRequestStatus, PublicError>) in }
purchases.beginRefundRequest(forEntitlement: "") { (_: Result<RefundRequestStatus, PublicError>) in }
purchases.beginRefundRequestForActiveEntitlement { (_: Result<RefundRequestStatus, PublicError>) in }
#endif
}

Expand Down

0 comments on commit 12cf786

Please sign in to comment.