Skip to content

Commit

Permalink
Add comment explaining data structure
Browse files Browse the repository at this point in the history
  • Loading branch information
tonidero committed Jan 21, 2025
1 parent 88fe43f commit 28e3f71
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions Sources/Error Handling/PurchasesError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,32 @@ extension PurchasesError {
/// let error = ErrorUtils.unknownError().asPublicError
/// let errorCode = error as? ErrorCode
/// ```
///
/// Info about the root error can be accessed in userInfo.
/// Example:
/// ```
/// let error = ErrorUtils.unknownError().asPublicError
/// let rootErrorInfo = error.userInfo["rc_root_error"] as? [String: Any]
/// let rootErrorCode = rootErrorInfo?["code"] as? Int
/// let rootErrorDomain = rootErrorInfo?["domain"] as? String
/// let rootErrorLocalizedDescription = rootErrorInfo?["localizedDescription"] as? String
/// ```
///
/// If the root error comes from StoreKit, some extra info will be added to the root error.
/// Example:
/// ```
/// let error = ErrorUtils.unknownError().asPublicError
/// let rootErrorInfo = error.userInfo["rc_root_error"] as? [String: Any]
/// let storeKitErrorInfo = rootErrorInfo?["storeKitError"] as? [String: Any]
/// let storeKitErrorDescription = storeKitErrorInfo?["description"] as? String
/// // If it's a SKError:
/// let skErrorCode = storeKitErrorInfo?["skErrorCode"] as? Int
/// // If it's a StoreKitError.networkError:
/// let urlErrorCode = storeKitErrorInfo?["urlErrorCode"] as? Int
/// let urlErrorFailingUrl = storeKitErrorInfo?["urlErrorFailingUrl"] as? String
/// // If it's a StoreKitError.systemError:
/// let systemErrorDescription = storeKitErrorInfo?["systemErrorDescription"] as? Int
/// ```
var asPublicError: PublicError {
let rootError: Error = self.rootError(from: self)
let rootNSError = rootError as NSError
Expand Down

0 comments on commit 28e3f71

Please sign in to comment.