Skip to content
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 .github/workflows/verify-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ jobs:
verify-pr:
name: Verify PR
runs-on: macos-14-xlarge
needs: lint

steps:
- name: Checkout repository
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1530"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES"
buildArchitectures = "Automatic">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "CheckoutNetwork"
BuildableName = "CheckoutNetwork"
BlueprintName = "CheckoutNetwork"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "CheckoutNetworkFakeClient"
BuildableName = "CheckoutNetworkFakeClient"
BlueprintName = "CheckoutNetworkFakeClient"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "CheckoutNetworkTests"
BuildableName = "CheckoutNetworkTests"
BlueprintName = "CheckoutNetworkTests"
ReferencedContainer = "container:">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "CheckoutNetwork"
BuildableName = "CheckoutNetwork"
BlueprintName = "CheckoutNetwork"
ReferencedContainer = "container:">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1530"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES"
buildArchitectures = "Automatic">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "CheckoutNetworkFakeClient"
BuildableName = "CheckoutNetworkFakeClient"
BlueprintName = "CheckoutNetworkFakeClient"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "CheckoutNetworkFakeClient"
BuildableName = "CheckoutNetworkFakeClient"
BlueprintName = "CheckoutNetworkFakeClient"
ReferencedContainer = "container:">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1530"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES"
buildArchitectures = "Automatic">
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "CheckoutNetworkTests"
BuildableName = "CheckoutNetworkTests"
BlueprintName = "CheckoutNetworkTests"
ReferencedContainer = "container:">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
6 changes: 3 additions & 3 deletions Sources/CheckoutNetwork/CheckoutClientInterface.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import Foundation
public protocol CheckoutClientInterface {

/// Completion handler that will return a result containing a decodable object or an error
typealias CompletionHandler<T> = ((Result<T, Error>) -> Void)
typealias CompletionHandler<T> = ((Result<T, CheckoutNetworkError>) -> Void)

/// Completion handler that will return errors if it fails or nothing if it completes as expected
typealias NoDataResponseCompletionHandler = ((Error?) -> Void)
typealias NoDataResponseCompletionHandler = ((CheckoutNetworkError?) -> Void)

// MARK: Traditional Base Methods

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public extension CheckoutNetworkClient {

func runRequest<T: Decodable>(with configuration: RequestConfiguration) async throws -> T {
return try await withCheckedThrowingContinuation { continuation in
runRequest(with: configuration) { (result: Result<T, Error>) in
runRequest(with: configuration) { (result: Result<T, CheckoutNetworkError>) in
switch result {
case .success(let response):
continuation.resume(returning: response)
Expand All @@ -24,7 +24,7 @@ public extension CheckoutNetworkClient {

func runRequest(with configuration: RequestConfiguration) async throws {
return try await withCheckedThrowingContinuation { continuation in
runRequest(with: configuration) { (error: Error?) in
runRequest(with: configuration) { (error: CheckoutNetworkError?) in

guard let error = error else {
continuation.resume(returning: Void())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation

extension CheckoutNetworkClient {
func getErrorFromResponse(_ response: URLResponse?, data: Data?) -> Error? {
func getErrorFromResponse(_ response: URLResponse?, data: Data?) -> CheckoutNetworkError? {
guard let response = response as? HTTPURLResponse else {
return CheckoutNetworkError.invalidURLResponse
}
Expand Down
9 changes: 5 additions & 4 deletions Sources/CheckoutNetwork/CheckoutNetworkClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ public class CheckoutNetworkClient: CheckoutClientInterface {
self?.tasks.removeValue(forKey: taskID)
guard let self = self else { return }
if let error = error {
completionHandler(.failure(self.convertDataTaskErrorsToCheckoutNetworkError(error: error)))
completionHandler(.failure(self.convertDataTaskErrorsToCheckoutNetworkError(error: error)))
return
}

guard let data = data else {
completionHandler(.failure(CheckoutNetworkError.noDataResponseReceived))
completionHandler(.failure(.noDataResponseReceived))
return
}

Expand All @@ -53,7 +53,7 @@ public class CheckoutNetworkClient: CheckoutClientInterface {

completionHandler(.success(dataResponse))
} catch {
completionHandler(.failure(error))
completionHandler(.failure(.decoding(errorDescription: error.localizedDescription)))
}
}
self.tasks[taskID] = task
Expand All @@ -69,8 +69,9 @@ public class CheckoutNetworkClient: CheckoutClientInterface {
let task = session.dataTask(with: request) { [weak self] data, response, error in
self?.tasks.removeValue(forKey: taskID)
guard let self = self else { return }

if let error = error {
completionHandler(error)
completionHandler(self.convertDataTaskErrorsToCheckoutNetworkError(error: error))
return
}
if let responseError = self.getErrorFromResponse(response, data: data) {
Expand Down
10 changes: 9 additions & 1 deletion Sources/CheckoutNetwork/CheckoutNetworkError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,15 @@ public enum CheckoutNetworkError: LocalizedError, Equatable {
/// When a response could not be bound to an instance of HTTPURLResponse
case invalidURLResponse

/// A decoding error has been received while decoding the API response
case decoding(errorDescription: String)

/// Network response was not in the 200 range
case unexpectedHTTPResponse(code: Int)

/// Network call and completion appear valid but no data was returned making the parsing impossible. Use runRequest method with NoDataResponseCompletionHandler if no data is expected (HTTP 204 is a success case with no content being returned)
/// Network call and completion appear valid but no data was returned making the parsing impossible.
/// Use runRequest method with NoDataResponseCompletionHandler if no data is expected
/// Refresher: HTTP 204 is a success case with no content being returned
case noDataResponseReceived

/// Network response returned with HTTP Code 422
Expand Down Expand Up @@ -48,6 +53,9 @@ public enum CheckoutNetworkError: LocalizedError, Equatable {
case .invalidURLResponse:
return "Could not instantiate an HTTPURLResponse with the received response value"

case .decoding(let errorDescription):
return errorDescription

case .unexpectedHTTPResponse(let code):
return "Received an unexpected HTTP response: \(code)"

Expand Down
Loading
Loading