Enhanced error handling.

This commit is contained in:
Maurice Parker 2020-12-10 17:12:04 -06:00
parent 2fbbdce46c
commit fce8070ae7
1 changed files with 10 additions and 1 deletions

View File

@ -15,6 +15,7 @@ import os.log
import Secrets import Secrets
public enum ReaderAPIAccountDelegateError: String, Error { public enum ReaderAPIAccountDelegateError: String, Error {
case unknown = "An unknown error occurred."
case invalidParameter = "There was an invalid parameter passed." case invalidParameter = "There was an invalid parameter passed."
case invalidResponse = "There was an invalid response from the server." case invalidResponse = "There was an invalid response from the server."
} }
@ -182,6 +183,8 @@ final class ReaderAPIAccountDelegate: AccountDelegate {
os_log(.debug, log: log, "Refreshing article statuses...") os_log(.debug, log: log, "Refreshing article statuses...")
let group = DispatchGroup() let group = DispatchGroup()
var errorOccurred = false
group.enter() group.enter()
caller.retrieveItemIDs(type: .unread) { result in caller.retrieveItemIDs(type: .unread) { result in
switch result { switch result {
@ -190,6 +193,7 @@ final class ReaderAPIAccountDelegate: AccountDelegate {
group.leave() group.leave()
} }
case .failure(let error): case .failure(let error):
errorOccurred = true
os_log(.info, log: self.log, "Retrieving unread entries failed: %@.", error.localizedDescription) os_log(.info, log: self.log, "Retrieving unread entries failed: %@.", error.localizedDescription)
group.leave() group.leave()
} }
@ -204,6 +208,7 @@ final class ReaderAPIAccountDelegate: AccountDelegate {
group.leave() group.leave()
} }
case .failure(let error): case .failure(let error):
errorOccurred = true
os_log(.info, log: self.log, "Retrieving starred entries failed: %@.", error.localizedDescription) os_log(.info, log: self.log, "Retrieving starred entries failed: %@.", error.localizedDescription)
group.leave() group.leave()
} }
@ -212,9 +217,13 @@ final class ReaderAPIAccountDelegate: AccountDelegate {
group.notify(queue: DispatchQueue.main) { group.notify(queue: DispatchQueue.main) {
os_log(.debug, log: self.log, "Done refreshing article statuses.") os_log(.debug, log: self.log, "Done refreshing article statuses.")
if errorOccurred {
completion(.failure(ReaderAPIAccountDelegateError.unknown))
} else {
completion(.success(())) completion(.success(()))
} }
} }
}
func importOPML(for account:Account, opmlFile: URL, completion: @escaping (Result<Void, Error>) -> Void) { func importOPML(for account:Account, opmlFile: URL, completion: @escaping (Result<Void, Error>) -> Void) {
} }