mirror of
https://github.com/RevenueCat/purchases-ios
synced 2026-11-10 22:45:55 +05:45
Follow up to #1429. For #695. This was duplicated in all operations. `HTTPClient` now only forwards `Result.success` if the request actually succeeded, leaving each `NetworkOperation` to just parse the body (which will become part of `HTTPClient` too). Other changes: - Simplified logic for when to retry requests in `HTTPClient` by using a new `Result.asOptionalResult` - Removed several response handlers that don't need to do anything anymore - Removed several tests that were basically duplicated: - The `finishable` checks are already tested as part of `ErrorResponse`. - All the checks for the error details are also part of `ErrorResponse`. - No longer need to have a test for each type of failed response since that's part of `HTTPClient` tests now.
41 lines
815 B
Swift
41 lines
815 B
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
|
|
//
|
|
// Optional+Extensions.swift
|
|
//
|
|
// Created by Nacho Soto on 3/30/22.
|
|
|
|
import Foundation
|
|
|
|
/// Protocol definition to be able to use `Optional` as a type.
|
|
internal protocol OptionalType {
|
|
|
|
associatedtype Wrapped
|
|
|
|
var asOptional: Wrapped? { get }
|
|
|
|
}
|
|
|
|
extension Optional: OptionalType {
|
|
|
|
var asOptional: Wrapped? { return self }
|
|
|
|
}
|
|
|
|
// MARK: -
|
|
|
|
internal extension Optional where Wrapped == String {
|
|
|
|
/// Returns `nil` if `self` is an empty string.
|
|
var notEmpty: String? {
|
|
return self.flatMap { $0.notEmpty }
|
|
}
|
|
|
|
}
|