diff --git a/apple/OmnivoreKit/Sources/Services/DataService/Mutations/SaveArticle.swift b/apple/OmnivoreKit/Sources/Services/DataService/Mutations/SaveArticle.swift index cc7352b41..bd1b0fdfa 100644 --- a/apple/OmnivoreKit/Sources/Services/DataService/Mutations/SaveArticle.swift +++ b/apple/OmnivoreKit/Sources/Services/DataService/Mutations/SaveArticle.swift @@ -219,14 +219,3 @@ public extension DataService { .eraseToAnyPublisher() } } - -private extension SaveArticleError { - static func make(from httpError: HttpError) -> SaveArticleError { - switch httpError { - case .network, .timeout: - return .network - case .badpayload, .badURL, .badstatus, .cancelled: - return .unknown(description: httpError.localizedDescription) - } - } -} diff --git a/apple/OmnivoreKit/Sources/Services/DataService/Mutations/SavePage.swift b/apple/OmnivoreKit/Sources/Services/DataService/Mutations/SavePage.swift index a6241f260..ee2c54733 100644 --- a/apple/OmnivoreKit/Sources/Services/DataService/Mutations/SavePage.swift +++ b/apple/OmnivoreKit/Sources/Services/DataService/Mutations/SavePage.swift @@ -63,7 +63,7 @@ public extension DataService { } } -private extension SaveArticleError { +extension SaveArticleError { static func make(from httpError: HttpError) -> SaveArticleError { switch httpError { case .network, .timeout: diff --git a/apple/OmnivoreKit/Sources/Services/DataService/Mutations/SaveUrl.swift b/apple/OmnivoreKit/Sources/Services/DataService/Mutations/SaveUrl.swift index 3a2ba77e7..6f29d8e04 100644 --- a/apple/OmnivoreKit/Sources/Services/DataService/Mutations/SaveUrl.swift +++ b/apple/OmnivoreKit/Sources/Services/DataService/Mutations/SaveUrl.swift @@ -1,11 +1,9 @@ -import Combine import Foundation import Models import SwiftGraphQL public extension DataService { - // swiftlint:disable:next line_length - func saveUrlPublisher(pageScrapePayload: PageScrapePayload, requestId: String) -> AnyPublisher { + func saveURL(pageScrapePayload: PageScrapePayload, requestId: String) async throws { enum MutationResult { case saved(requestId: String, url: String) case error(errorCode: Enums.SaveErrorCode) @@ -31,44 +29,32 @@ public extension DataService { let path = appEnvironment.graphqlPath let headers = networker.defaultHeaders - return Deferred { - Future { promise in - send(mutation, to: path, headers: headers) { result in - switch result { - case let .success(payload): - if let graphqlError = payload.errors { - promise(.failure(.unknown(description: graphqlError.first.debugDescription))) - } - - switch payload.data { - case .saved: - promise(.success(())) - case let .error(errorCode: errorCode): - switch errorCode { - case .unauthorized: - promise(.failure(.unauthorized)) - default: - promise(.failure(.unknown(description: errorCode.rawValue))) - } - } - case let .failure(error): - promise(.failure(SaveError.make(from: error))) + return try await withCheckedThrowingContinuation { continuation in + send(mutation, to: path, headers: headers) { result in + switch result { + case let .success(payload): + if let graphqlError = payload.errors { + continuation.resume( + throwing: SaveArticleError.unknown(description: graphqlError.first.debugDescription) + ) + return } + + switch payload.data { + case .saved: + continuation.resume() + case let .error(errorCode: errorCode): + switch errorCode { + case .unauthorized: + continuation.resume(throwing: SaveArticleError.unauthorized) + default: + continuation.resume(throwing: SaveArticleError.unknown(description: errorCode.rawValue)) + } + } + case let .failure(error): + continuation.resume(throwing: SaveArticleError.make(from: error)) } } } - .receive(on: DispatchQueue.main) - .eraseToAnyPublisher() - } -} - -private extension SaveError { - static func make(from httpError: HttpError) -> SaveArticleError { - switch httpError { - case .network, .timeout: - return .network - case .badpayload, .badURL, .badstatus, .cancelled: - return .unknown(description: httpError.localizedDescription) - } } }