mirror of
https://github.com/writeas/writefreely-swiftui-multiplatform.git
synced 2024-11-15 01:11:02 +00:00
Add default values for some error strings
This commit is contained in:
parent
dfb3a08608
commit
11d2e41ab5
@ -24,7 +24,7 @@ struct AccountView: View {
|
||||
if let error = model.currentError {
|
||||
self.errorHandling.handle(error: error)
|
||||
} else {
|
||||
self.errorHandling.handle(error: AppError.genericError(""))
|
||||
self.errorHandling.handle(error: AppError.genericError())
|
||||
}
|
||||
model.hasError = false
|
||||
}
|
||||
|
@ -101,13 +101,13 @@ extension UserDefaultsError: LocalizedError {
|
||||
enum LocalStoreError: Error {
|
||||
case couldNotSaveContext
|
||||
case couldNotFetchCollections
|
||||
case couldNotFetchPosts(String)
|
||||
case couldNotFetchPosts(String = "")
|
||||
case couldNotPurgePublishedPosts
|
||||
case couldNotPurgeCollections
|
||||
case couldNotLoadStore(String)
|
||||
case couldNotMigrateStore(String)
|
||||
case couldNotDeleteStoreAfterMigration(String)
|
||||
case genericError(String)
|
||||
case genericError(String = "")
|
||||
}
|
||||
|
||||
extension LocalStoreError: LocalizedError {
|
||||
@ -148,7 +148,7 @@ extension LocalStoreError: LocalizedError {
|
||||
enum AppError: Error {
|
||||
case couldNotGetLoggedInClient
|
||||
case couldNotGetPostId
|
||||
case genericError(String)
|
||||
case genericError(String = "")
|
||||
}
|
||||
|
||||
extension AppError: LocalizedError {
|
||||
|
@ -39,7 +39,7 @@ extension WriteFreelyModel {
|
||||
var secItem: CFTypeRef?
|
||||
let status = SecItemCopyMatching(query as CFDictionary, &secItem)
|
||||
guard status != errSecItemNotFound else {
|
||||
return nil
|
||||
throw KeychainError.couldNotFetchAccessToken
|
||||
}
|
||||
guard status == errSecSuccess else {
|
||||
throw KeychainError.couldNotFetchAccessToken
|
||||
@ -47,7 +47,7 @@ extension WriteFreelyModel {
|
||||
guard let existingSecItem = secItem as? [String: Any],
|
||||
let tokenData = existingSecItem[kSecValueData as String] as? Data,
|
||||
let token = String(data: tokenData, encoding: .utf8) else {
|
||||
return nil
|
||||
throw KeychainError.couldNotFetchAccessToken
|
||||
}
|
||||
return token
|
||||
}
|
||||
|
@ -87,6 +87,7 @@ final class WriteFreelyModel: ObservableObject {
|
||||
self.fetchUserPosts()
|
||||
} catch {
|
||||
self.currentError = KeychainError.couldNotFetchAccessToken
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -59,21 +59,19 @@ struct ContentView: View {
|
||||
|
||||
Text("Select a post, or create a new local draft.")
|
||||
.foregroundColor(.secondary)
|
||||
|
||||
EmptyView()
|
||||
}
|
||||
.environmentObject(model)
|
||||
.onChange(of: model.hasError) { value in
|
||||
if value {
|
||||
if let error = model.currentError {
|
||||
self.errorHandling.handle(error: error)
|
||||
} else {
|
||||
self.errorHandling.handle(error: AppError.genericError(""))
|
||||
self.errorHandling.handle(error: AppError.genericError())
|
||||
}
|
||||
model.hasError = false
|
||||
}
|
||||
}
|
||||
}
|
||||
.environmentObject(model)
|
||||
}
|
||||
}
|
||||
|
||||
struct ContentView_Previews: PreviewProvider {
|
||||
|
@ -133,7 +133,7 @@ struct PostListView: View {
|
||||
if let error = model.currentError {
|
||||
self.errorHandling.handle(error: error)
|
||||
} else {
|
||||
self.errorHandling.handle(error: AppError.genericError(""))
|
||||
self.errorHandling.handle(error: AppError.genericError())
|
||||
}
|
||||
model.hasError = false
|
||||
}
|
||||
@ -165,7 +165,7 @@ struct PostListView: View {
|
||||
if let error = model.currentError {
|
||||
self.errorHandling.handle(error: error)
|
||||
} else {
|
||||
self.errorHandling.handle(error: AppError.genericError)
|
||||
self.errorHandling.handle(error: AppError.genericError())
|
||||
}
|
||||
model.hasError = false
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user