Skip to content

Commit

Permalink
Expose fetchRegions() to allow handling error (#307)
Browse files Browse the repository at this point in the history
  • Loading branch information
nighthawk authored Sep 21, 2023
1 parent 04118f0 commit 1108d6f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Sources/TripKit/managers/TKRegionManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public class TKRegionManager: NSObject {
let response = try JSONDecoder().decode(TKAPI.RegionsResponse.self, from: data)
updateRegions(from: response)
} catch {
assertionFailure()
TKLog.warn("Couldn't load regions from cache: \(error)")
assertionFailure()
}
}

Expand Down
12 changes: 10 additions & 2 deletions Sources/TripKit/server/TKServer+Regions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ extension TKRegionManager {

/// Fetched the list of regions and updates `TKRegionManager`'s cache
///
/// Equivalent to `updateRegions(forced:) async throws`, but ignores the error.
///
/// Recommended to call from the application delegate.
/// - Parameter forced: Set true to force overwriting the internal cache
public func updateRegions(forced: Bool = false) {
Task {
try? await fetchRegions(forced: forced)
}
}

@available(*, renamed: "requireRegions()")
public func requireRegions(completion: @escaping (Result<Void, Error>) -> Void) {
guard !hasRegions else {
Expand All @@ -46,7 +48,13 @@ extension TKRegionManager {
}
}

private func fetchRegions(forced: Bool) async throws {
/// Fetched the list of regions and updates `TKRegionManager`'s cache
///
/// Equivalent to `updateRegions(forced:)`.
///
/// Recommended to call from the application delegate.
/// - Parameter forced: Set true to force overwriting the internal cache
public func fetchRegions(forced: Bool) async throws {
let regionsURL: URL
if let customBaseURL = TKServer.customBaseURL {
guard let url = URL(string: customBaseURL) else {
Expand Down

0 comments on commit 1108d6f

Please sign in to comment.