Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Purchases.beginRefundRequest: ensured errors are PublicError #1913

Merged
merged 1 commit into from
Sep 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, *)
tonidero marked this conversation as resolved.
Show resolved Hide resolved
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