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 couldNotSaveContext
|
||||||
case couldNotFetchCollections
|
case couldNotFetchCollections
|
||||||
case couldNotFetchPosts(String = "")
|
case couldNotFetchPosts(String = "")
|
||||||
case couldNotPurgePublishedPosts
|
case couldNotPurgePosts(String = "")
|
||||||
case couldNotPurgeCollections
|
case couldNotPurgeCollections
|
||||||
case couldNotLoadStore(String)
|
case couldNotLoadStore(String)
|
||||||
case couldNotMigrateStore(String)
|
case couldNotMigrateStore(String)
|
||||||
@ -123,8 +123,12 @@ extension LocalStoreError: LocalizedError {
|
|||||||
} else {
|
} else {
|
||||||
return NSLocalizedString("Failed to fetch \(postFilter) posts from local store.", comment: "")
|
return NSLocalizedString("Failed to fetch \(postFilter) posts from local store.", comment: "")
|
||||||
}
|
}
|
||||||
case .couldNotPurgePublishedPosts:
|
case .couldNotPurgePosts(let postFilter):
|
||||||
return NSLocalizedString("Failed to purge published posts from local store.", comment: "")
|
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:
|
case .couldNotPurgeCollections:
|
||||||
return NSLocalizedString("Failed to purge cached collections", comment: "")
|
return NSLocalizedString("Failed to purge cached collections", comment: "")
|
||||||
case .couldNotLoadStore(let errorDescription):
|
case .couldNotLoadStore(let errorDescription):
|
||||||
|
@ -41,7 +41,11 @@ extension WriteFreelyModel {
|
|||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
self.account.logout()
|
self.account.logout()
|
||||||
LocalStorageManager.standard.purgeUserCollections()
|
LocalStorageManager.standard.purgeUserCollections()
|
||||||
self.posts.purgePublishedPosts()
|
do {
|
||||||
|
try self.posts.purgePublishedPosts()
|
||||||
|
} catch {
|
||||||
|
self.currentError = error
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
self.currentError = KeychainError.couldNotPurgeAccessToken
|
self.currentError = KeychainError.couldNotPurgeAccessToken
|
||||||
@ -56,7 +60,11 @@ extension WriteFreelyModel {
|
|||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
self.account.logout()
|
self.account.logout()
|
||||||
LocalStorageManager.standard.purgeUserCollections()
|
LocalStorageManager.standard.purgeUserCollections()
|
||||||
self.posts.purgePublishedPosts()
|
do {
|
||||||
|
try self.posts.purgePublishedPosts()
|
||||||
|
} catch {
|
||||||
|
self.currentError = error
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
self.currentError = KeychainError.couldNotPurgeAccessToken
|
self.currentError = KeychainError.couldNotPurgeAccessToken
|
||||||
|
@ -9,7 +9,7 @@ class PostListModel: ObservableObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func purgePublishedPosts() {
|
func purgePublishedPosts() throws {
|
||||||
let fetchRequest: NSFetchRequest<NSFetchRequestResult> = NSFetchRequest(entityName: "WFAPost")
|
let fetchRequest: NSFetchRequest<NSFetchRequestResult> = NSFetchRequest(entityName: "WFAPost")
|
||||||
fetchRequest.predicate = NSPredicate(format: "status != %i", 0)
|
fetchRequest.predicate = NSPredicate(format: "status != %i", 0)
|
||||||
let deleteRequest = NSBatchDeleteRequest(fetchRequest: fetchRequest)
|
let deleteRequest = NSBatchDeleteRequest(fetchRequest: fetchRequest)
|
||||||
@ -17,7 +17,7 @@ class PostListModel: ObservableObject {
|
|||||||
do {
|
do {
|
||||||
try LocalStorageManager.standard.container.viewContext.executeAndMergeChanges(using: deleteRequest)
|
try LocalStorageManager.standard.container.viewContext.executeAndMergeChanges(using: deleteRequest)
|
||||||
} catch {
|
} catch {
|
||||||
print("Error: Failed to purge cached posts.")
|
throw LocalStoreError.couldNotPurgePosts("cached")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user