mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2024-12-22 23:58:36 +01:00
Add logging to FeedFinder.
This commit is contained in:
parent
9d747a99c9
commit
58ba14cd78
@ -11,9 +11,12 @@ import Parser
|
|||||||
import ParserObjC
|
import ParserObjC
|
||||||
import Web
|
import Web
|
||||||
import CommonErrors
|
import CommonErrors
|
||||||
|
import os.log
|
||||||
|
|
||||||
@MainActor public final class FeedFinder {
|
@MainActor public final class FeedFinder {
|
||||||
|
|
||||||
|
private static let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "FeedFinder")
|
||||||
|
|
||||||
@MainActor public static func find(url: URL) async throws -> Set<FeedSpecifier> {
|
@MainActor public static func find(url: URL) async throws -> Set<FeedSpecifier> {
|
||||||
|
|
||||||
try await withCheckedThrowingContinuation { continuation in
|
try await withCheckedThrowingContinuation { continuation in
|
||||||
@ -36,6 +39,7 @@ import CommonErrors
|
|||||||
MainActor.assumeIsolated {
|
MainActor.assumeIsolated {
|
||||||
|
|
||||||
if response?.forcedStatusCode == 404 {
|
if response?.forcedStatusCode == 404 {
|
||||||
|
logger.error("FeedFinder: 404 for \(url)")
|
||||||
if var urlComponents = URLComponents(url: url, resolvingAgainstBaseURL: false), urlComponents.host == "micro.blog" {
|
if var urlComponents = URLComponents(url: url, resolvingAgainstBaseURL: false), urlComponents.host == "micro.blog" {
|
||||||
urlComponents.path = "\(urlComponents.path).json"
|
urlComponents.path = "\(urlComponents.path).json"
|
||||||
if let newURLString = urlComponents.url?.absoluteString {
|
if let newURLString = urlComponents.url?.absoluteString {
|
||||||
@ -49,31 +53,37 @@ import CommonErrors
|
|||||||
}
|
}
|
||||||
|
|
||||||
if let error = error {
|
if let error = error {
|
||||||
|
logger.error("FeedFinder: error for \(url) - \(error)")
|
||||||
completion(.failure(error))
|
completion(.failure(error))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
guard let data = data, let response = response else {
|
guard let data, !data.isEmpty, let response else {
|
||||||
|
logger.error("FeedFinder: missing response and/or data for \(url)")
|
||||||
completion(.failure(AccountError.createErrorNotFound))
|
completion(.failure(AccountError.createErrorNotFound))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !response.statusIsOK || data.isEmpty {
|
if !response.statusIsOK {
|
||||||
|
logger.error("FeedFinder: non-OK response for \(url) - \(response.forcedStatusCode)")
|
||||||
completion(.failure(AccountError.createErrorNotFound))
|
completion(.failure(AccountError.createErrorNotFound))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if FeedFinder.isFeed(data, url.absoluteString) {
|
if FeedFinder.isFeed(data, url.absoluteString) {
|
||||||
|
logger.info("FeedFinder: is feed \(url)")
|
||||||
let feedSpecifier = FeedSpecifier(title: nil, urlString: url.absoluteString, source: .UserEntered, orderFound: 1)
|
let feedSpecifier = FeedSpecifier(title: nil, urlString: url.absoluteString, source: .UserEntered, orderFound: 1)
|
||||||
completion(.success(Set([feedSpecifier])))
|
completion(.success(Set([feedSpecifier])))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !FeedFinder.isHTML(data) {
|
if !FeedFinder.isHTML(data) {
|
||||||
|
logger.error("FeedFinder: not feed and not HTML \(url)")
|
||||||
completion(.failure(AccountError.createErrorNotFound))
|
completion(.failure(AccountError.createErrorNotFound))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.info("FeedFinder: finding feeds in HTML \(url)")
|
||||||
FeedFinder.findFeedsInHTMLPage(htmlData: data, urlString: url.absoluteString, completion: completion)
|
FeedFinder.findFeedsInHTMLPage(htmlData: data, urlString: url.absoluteString, completion: completion)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user