mirror of
https://github.com/RevenueCat/purchases-ios
synced 2026-11-11 22:55:55 +05:45
Closes #695 and finishes [CF-195]. Depends on ~~#1431, #1432, #1433, #1437~~. ## Goals: - [x] Handle all requests / response / deserialization errors in `HTTPClient`. Clients of `HTTPClient` will only have to handle the "happy" path: #1431 - [x] `HTTPClient` shouldn't return `Result.success` with failed responses, forcing clients to verify the response is actually a failure: https://github.com/RevenueCat/purchases-ios/pull/1431 - [x] Abstract error response deserialization / error creation: #1427 - [x] Abstract attribute error parsing: #1427 - [x] Move response deserialization to `HTTPClient` based on a `ResponseType: Decodable` type, so the completion block will simply return a `Result<HTTPResponse<ResponseType>, Error>` - [x] `ETagManager` should store response `Data` instead of a deserialized `[String: Any]` - [x] Improved error types in `HTTPClient` to fix tests: #1437 - [x] Dealt with non-backwards compatible `ETagManager: #1438 ## Changes: - Replaced `HTTPResponse`'s body from `[String: Any]` to a generic `HTTPResponseBody`. - Created `HTTPResponseBody` to abstract `Decodable` and provide some default implementations for types like `Data,` `[String: Any]` (for backwards compatibility to types that aren't `Decodable` yet), and `Decodable` itself. - New `HTTPResponse.Result` typealias (`Result<HTTPResponse<HTTPResponseBody>, Error>`) used everywhere. This will allow replacing `Error` with a more specific `Error` so we can forward known typed errors, and make sure that we don't end up with the wrong error type, or with a very complex error hierarchy and the details buried in `underlyingError`. - Each layer (only a few for now) has its own error type: `NetworkError`, `BackendError`, `OfferingsManager.Error`. - `HTTPClient` for example has to produce `NetworkError`, operations produce `BackendError` - The parent `BackendError` can have specific errors like `.missingAppUserID`, but also be simply a child error `case networkError(NetworkError)` - All of these conform to a `ErrorCodeConvertible`, so there is a single point of code that converts from simple and readable errors (like `BackendError.emptySubscriberAttributes`, `.unexpectedBackendResponse(.loginResponseDecoding)`) into errors with all the context using `ErrorUtils` - Converted `DNSError` into `NetworkError.dnsError`. Its functionality remains unchanged. - Removed `Backend.RCSuccessfullySyncedKey` and `ErrorDetails.finishableKey` in favor of tested properties on `NetworkError` ### Leftovers There's a few things I've decided to not finish for now: - [ ] `CustomerInfo` still does't conform to `Decodable` (manual deserialization is still supported by the current system): #1496 - `SubscriberAttributeDict` could also be `Codable` - [x] Replace `OfferingsFactory` with `Decodable`: #1435 [CF-195]: https://revenuecats.atlassian.net/browse/CF-195?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
81 lines
2.6 KiB
Swift
81 lines
2.6 KiB
Swift
//
|
|
// Copyright RevenueCat Inc. All Rights Reserved.
|
|
//
|
|
// Licensed under the MIT License (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// https://opensource.org/licenses/MIT
|
|
//
|
|
// ReceiptStrings.swift
|
|
//
|
|
// Created by Tina Nguyen on 12/11/20.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
// swiftlint:disable identifier_name
|
|
enum ReceiptStrings {
|
|
|
|
case data_object_identifer_not_found_receipt
|
|
case force_refreshing_receipt
|
|
case loaded_receipt(url: URL)
|
|
case no_sandbox_receipt_intro_eligibility
|
|
case no_sandbox_receipt_restore
|
|
case parse_receipt_locally_error(error: Error)
|
|
case parsing_receipt_failed(fileName: String, functionName: String)
|
|
case parsing_receipt_success
|
|
case parsing_receipt
|
|
case refreshing_empty_receipt
|
|
case unable_to_load_receipt
|
|
|
|
}
|
|
|
|
extension ReceiptStrings: CustomStringConvertible {
|
|
|
|
var description: String {
|
|
switch self {
|
|
|
|
case .data_object_identifer_not_found_receipt:
|
|
return "The data object identifier couldn't be found on the receipt."
|
|
|
|
case .force_refreshing_receipt:
|
|
return "Force refreshing the receipt to get latest transactions from Apple."
|
|
|
|
case .loaded_receipt(let url):
|
|
return "Loaded receipt from url \(url.absoluteString)"
|
|
|
|
case .no_sandbox_receipt_intro_eligibility:
|
|
return "App running on sandbox without a receipt file. " +
|
|
"Unable to determine into eligibility unless you've purchased " +
|
|
"before and there is a receipt available."
|
|
|
|
case .no_sandbox_receipt_restore:
|
|
return "App running in sandbox without a receipt file. Restoring " +
|
|
"transactions won't work until a purchase is made to generate a receipt. " +
|
|
"This should not happen in production unless user is logged out of Apple account."
|
|
|
|
case .parse_receipt_locally_error(let error):
|
|
return "There was an error when trying to parse the receipt " +
|
|
"locally, details: \(error.localizedDescription)"
|
|
|
|
case .parsing_receipt_failed(let fileName, let functionName):
|
|
return "\(fileName)-\(functionName): Could not parse receipt, conservatively returning true"
|
|
|
|
case .parsing_receipt_success:
|
|
return "Receipt parsed successfully"
|
|
|
|
case .parsing_receipt:
|
|
return "Parsing receipt"
|
|
|
|
case .refreshing_empty_receipt:
|
|
return "Receipt empty, refreshing"
|
|
|
|
case .unable_to_load_receipt:
|
|
return "Unable to load receipt, ensure you are logged in to a valid Apple account."
|
|
|
|
}
|
|
}
|
|
|
|
}
|