Skip to content

Commit

Permalink
Merge pull request #19 from bilaalrashid/bilaal/wrapping-result-as-th…
Browse files Browse the repository at this point in the history
…rows

Use .get() for wrapping Result methods as throws
  • Loading branch information
bilaalrashid authored Jul 9, 2024
2 parents 2373c69 + 510d022 commit 0120f1f
Showing 1 changed file with 5 additions and 40 deletions.
45 changes: 5 additions & 40 deletions Sources/BbcNews/BbcNews.swift
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,7 @@ public struct BbcNews {
/// - Parameter postcode: The first part of the user's UK postcode e.g. W1A.
/// - Returns: The index discovery page.
public func fetchIndexDiscoveryPageThrowing(postcode: String? = nil) async throws -> FDResult {
let result = await self.fetchIndexDiscoveryPage(postcode: postcode)

switch result {
case .success(let response):
return response
case .failure(let error):
throw error
}
return try await self.fetchIndexDiscoveryPage(postcode: postcode).get()
}

/// Fetches the main discovery page of the BBC News app i.e. the page shown in the Home tab.
Expand Down Expand Up @@ -207,14 +200,7 @@ public struct BbcNews {
/// - Parameter topicIds: The topic IDs to fetch.
/// - Returns: The fetched topic pages.
public func fetchTopicDiscoveryPagesThrowing(for topicIds: [String]) async throws -> [FDResult] {
let result = await self.fetchTopicDiscoveryPages(for: topicIds)

switch result {
case .success(let response):
return response
case .failure(let error):
throw error
}
return try await self.fetchTopicDiscoveryPages(for: topicIds).get()
}

/// Fetches the pages for multiple topics.
Expand Down Expand Up @@ -243,14 +229,7 @@ public struct BbcNews {
/// - Parameter topicId: The topic ID to fetch.
/// - Returns: The fetched topic page.
public func fetchTopicDiscoveryPageThrowing(for topicId: String) async throws -> FDResult {
let result = await self.fetchTopicDiscoveryPage(for: topicId)

switch result {
case .success(let response):
return response
case .failure(let error):
throw error
}
return try await self.fetchTopicDiscoveryPage(for: topicId).get()
}

/// Fetches the page for a specified topic.
Expand Down Expand Up @@ -285,14 +264,7 @@ public struct BbcNews {
/// - Parameter urlString: The absolute URL to fetch.
/// - Returns: The fetched page.
public func fetchThrowing(urlString: String) async throws -> FDResult {
let result = await self.fetch(urlString: urlString)

switch result {
case .success(let response):
return response
case .failure(let error):
throw error
}
return try await self.fetch(urlString: urlString).get()
}

/// Fetches a page from the BBC News API.
Expand All @@ -312,14 +284,7 @@ public struct BbcNews {
/// - Parameter url: The URL to fetch.
/// - Returns: The fetched page.
public func fetchThrowing(url: URL) async throws -> FDResult {
let result = await self.fetch(url: url)

switch result {
case .success(let response):
return response
case .failure(let error):
throw error
}
return try await self.fetch(url: url).get()
}

/// Fetches a page from the BBC News API.
Expand Down

0 comments on commit 0120f1f

Please sign in to comment.