mirror of
https://github.com/writeas/writefreely-swiftui-multiplatform.git
synced 2024-11-15 01:11:02 +00:00
Handle purging post errors
This commit is contained in:
parent
11d2e41ab5
commit
b017e21e06
@ -102,7 +102,7 @@ enum LocalStoreError: Error {
|
||||
case couldNotSaveContext
|
||||
case couldNotFetchCollections
|
||||
case couldNotFetchPosts(String = "")
|
||||
case couldNotPurgePublishedPosts
|
||||
case couldNotPurgePosts(String = "")
|
||||
case couldNotPurgeCollections
|
||||
case couldNotLoadStore(String)
|
||||
case couldNotMigrateStore(String)
|
||||
@ -123,8 +123,12 @@ extension LocalStoreError: LocalizedError {
|
||||
} else {
|
||||
return NSLocalizedString("Failed to fetch \(postFilter) posts from local store.", comment: "")
|
||||
}
|
||||
case .couldNotPurgePublishedPosts:
|
||||
return NSLocalizedString("Failed to purge published posts from local store.", comment: "")
|
||||
case .couldNotPurgePosts(let postFilter):
|
||||
if postFilter.isEmpty {
|
||||
return NSLocalizedString("Failed to purge \(postFilter) posts from local store.", comment: "")
|
||||
} else {
|
||||
return NSLocalizedString("Failed to purge posts from local store.", comment: "")
|
||||
}
|
||||
case .couldNotPurgeCollections:
|
||||
return NSLocalizedString("Failed to purge cached collections", comment: "")
|
||||
case .couldNotLoadStore(let errorDescription):
|
||||
|
@ -41,7 +41,11 @@ extension WriteFreelyModel {
|
||||
DispatchQueue.main.async {
|
||||
self.account.logout()
|
||||
LocalStorageManager.standard.purgeUserCollections()
|
||||
self.posts.purgePublishedPosts()
|
||||
do {
|
||||
try self.posts.purgePublishedPosts()
|
||||
} catch {
|
||||
self.currentError = error
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
self.currentError = KeychainError.couldNotPurgeAccessToken
|
||||
@ -56,7 +60,11 @@ extension WriteFreelyModel {
|
||||
DispatchQueue.main.async {
|
||||
self.account.logout()
|
||||
LocalStorageManager.standard.purgeUserCollections()
|
||||
self.posts.purgePublishedPosts()
|
||||
do {
|
||||
try self.posts.purgePublishedPosts()
|
||||
} catch {
|
||||
self.currentError = error
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
self.currentError = KeychainError.couldNotPurgeAccessToken
|
||||
|
@ -9,7 +9,7 @@ class PostListModel: ObservableObject {
|
||||
}
|
||||
}
|
||||
|
||||
func purgePublishedPosts() {
|
||||
func purgePublishedPosts() throws {
|
||||
let fetchRequest: NSFetchRequest<NSFetchRequestResult> = NSFetchRequest(entityName: "WFAPost")
|
||||
fetchRequest.predicate = NSPredicate(format: "status != %i", 0)
|
||||
let deleteRequest = NSBatchDeleteRequest(fetchRequest: fetchRequest)
|
||||
@ -17,7 +17,7 @@ class PostListModel: ObservableObject {
|
||||
do {
|
||||
try LocalStorageManager.standard.container.viewContext.executeAndMergeChanges(using: deleteRequest)
|
||||
} catch {
|
||||
print("Error: Failed to purge cached posts.")
|
||||
throw LocalStoreError.couldNotPurgePosts("cached")
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user