Less obnoxious error handling

This commit is contained in:
Arkadiusz Fal
2022-12-16 09:35:10 +01:00
parent a9c8053474
commit 4330856c5e
10 changed files with 97 additions and 25 deletions

View File

@@ -18,6 +18,8 @@ final class FeedModel: ObservableObject, CacheModel {
var storage: Storage<String, JSON>?
@Published var error: RequestError?
private var backgroundContext = PersistenceController.shared.container.newBackgroundContext()
var feed: Resource? {
@@ -79,6 +81,7 @@ final class FeedModel: ObservableObject, CacheModel {
onCompletion()
}
.onSuccess { response in
self.error = nil
if let videos: [Video] = response.typedContent() {
if paginating {
self.videos.append(contentsOf: videos)
@@ -89,9 +92,7 @@ final class FeedModel: ObservableObject, CacheModel {
}
}
}
.onFailure { error in
NavigationModel.shared.presentAlert(title: "Could not refresh Subscriptions", message: error.userMessage)
}
.onFailure { self.error = $0 }
}
}