Skip to content

Commit

Permalink
Move WooShippingLoadPackagesError to WooShippingStore
Browse files Browse the repository at this point in the history
  • Loading branch information
bozidarsevo committed Dec 20, 2024
1 parent af5e2eb commit 0ae53a6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,7 @@ final class WooShippingAddPackageViewModel: ObservableObject {

let result: Result<WooShippingPackagesResponse, WooShippingLoadPackagesError> = await withCheckedContinuation { continuation in
let loadPackagesAction = WooShippingAction.loadPackages(siteID: siteID) { result in
switch result {
case .success(let packagesResult):
continuation.resume(returning: .success(packagesResult))
case .failure(let error):
continuation.resume(returning: .failure(WooShippingLoadPackagesError.loadingFailed(error: error)))
}
continuation.resume(returning: result)
}
stores.dispatch(loadPackagesAction)
}
Expand Down Expand Up @@ -339,8 +334,3 @@ extension WooShippingCarrierPredefinedOptions {
return carrierPackages
}
}

public enum WooShippingLoadPackagesError: Error {
case loadingInProgress
case loadingFailed(error: Error)
}
2 changes: 1 addition & 1 deletion Yosemite/Yosemite/Actions/WooShippingAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public enum WooShippingAction: Action {
/// Fetch list of packages.
///
case loadPackages(siteID: Int64,
completion: (Result<WooShippingPackagesResponse, Error>) -> Void)
completion: (Result<WooShippingPackagesResponse, WooShippingLoadPackagesError>) -> Void)

/// Fetch list of packages.
///
Expand Down
9 changes: 7 additions & 2 deletions Yosemite/Yosemite/Stores/WooShippingStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,15 @@ private extension WooShippingStore {
}

func loadPackages(siteID: Int64,
completion: @escaping (Result<WooShippingPackagesResponse, Error>) -> Void) {
completion: @escaping (Result<WooShippingPackagesResponse, WooShippingLoadPackagesError>) -> Void) {
remote.loadPackages(siteID: siteID) { [weak self] result in
switch result {
case .success(let packages):
self?.upsertPackagesResponseInBackground(readOnlyPackages: packages, siteID: siteID) {
completion(.success(packages))
}
case .failure(let error):
completion(.failure(error))
completion(.failure(WooShippingLoadPackagesError.loadingFailed(error: error)))
}
}
}
Expand Down Expand Up @@ -470,3 +470,8 @@ public enum WooShippingLabelPurchaseError: Error {
/// No labels are returned by initial purchase request
case purchaseMissingLabels
}

public enum WooShippingLoadPackagesError: Error {
case loadingInProgress
case loadingFailed(error: Error)
}

0 comments on commit 0ae53a6

Please sign in to comment.