From faa31409cd76cd5097d70841cf8c0fe45a8f2f65 Mon Sep 17 00:00:00 2001 From: Aashna Narula Date: Fri, 15 Mar 2024 13:06:02 +0000 Subject: [PATCH] Update request to handle error cases --- .../CheckoutNetworkFakeClient.swift | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Sources/CheckoutNetworkFakeClient/CheckoutNetworkFakeClient.swift b/Sources/CheckoutNetworkFakeClient/CheckoutNetworkFakeClient.swift index c32bd88..7cee42a 100644 --- a/Sources/CheckoutNetworkFakeClient/CheckoutNetworkFakeClient.swift +++ b/Sources/CheckoutNetworkFakeClient/CheckoutNetworkFakeClient.swift @@ -13,6 +13,7 @@ final public class CheckoutNetworkFakeClient: CheckoutClientInterface { public var calledAsyncRequests: [RequestConfiguration] = [] public var dataToBeReturned: Decodable! + public var errorToBeThrown: CheckoutNetworkError? public func runRequest(with configuration: RequestConfiguration, completionHandler: @escaping CompletionHandler) { @@ -29,13 +30,19 @@ extension CheckoutNetworkFakeClient { public func runRequest(with configuration: CheckoutNetwork.RequestConfiguration) async throws -> T { calledAsyncRequests.append(configuration) // swiftlint:disable force_cast - return dataToBeReturned as! T + guard let error = errorToBeThrown else { + return dataToBeReturned as! T + } + throw error // swiftlint:enable force_cast } public func runRequest(with configuration: RequestConfiguration) async throws { calledAsyncRequests.append(configuration) try await Task.sleep(nanoseconds: 1 * 1_000_000_000) // 1 second - return () + guard let error = errorToBeThrown else { + return () + } + throw error } }