Add some logging to LocalAccountDelegate.

This commit is contained in:
Brent Simmons 2024-05-26 12:33:10 -07:00
parent b5d132717d
commit b0263c4ff3
2 changed files with 22 additions and 6 deletions

View File

@ -221,15 +221,16 @@ extension LocalAccountDelegate: FeedDownloaderDelegate {
func feedDownloader(_: FeedDownloader, requestCompletedForFeedURL feedURL: URL, response: URLResponse?, data: Data?, error: Error?) {
guard let account, let feed = account.existingFeed(urlString: feedURL.absoluteString) else {
if let error {
logger.debug("Error downloading: \(feedURL) - \(error)")
return
}
if let error {
logger.debug("Error downloading \(feed.url) - \(error)")
guard let response, let data, !data.isEmpty else {
logger.debug("Missing response and/or data: \(feedURL)")
return
}
guard let response, let data, !data.isEmpty else {
guard let account, let feed = account.existingFeed(urlString: feedURL.absoluteString) else {
return
}
@ -238,11 +239,12 @@ extension LocalAccountDelegate: FeedDownloaderDelegate {
func feedDownloader(_: FeedDownloader, requestCanceledForFeedURL feedURL: URL, response: URLResponse?, data: Data?, error: Error?, reason: FeedDownloader.CancellationReason) {
// nothing to do
logger.debug("Request canceled: \(feedURL) - \(reason)")
}
func feedDownloaderSessionDidComplete(_: FeedDownloader) {
logger.debug("Feed downloader session did complete")
account?.metadata.lastArticleFetchEndTime = Date()
}

View File

@ -25,11 +25,25 @@ public protocol FeedDownloaderDelegate: AnyObject {
/// Use this to download feeds directly (local and iCloud accounts).
@MainActor public final class FeedDownloader {
public enum CancellationReason {
public enum CancellationReason: CustomStringConvertible {
case suspended
case notFeedData
case unexpectedResponse
case notModified
public var description: String {
switch self {
case .suspended:
return "suspended"
case .notFeedData:
return "notFeedData"
case .unexpectedResponse:
return "unexpectedResponse"
case .notModified:
return "notModified"
}
}
}
public weak var delegate: FeedDownloaderDelegate?