Add default values for some error strings

This commit is contained in:
Angelo Stavrow 2022-05-23 15:12:33 -04:00
parent dfb3a08608
commit 11d2e41ab5
No known key found for this signature in database
GPG Key ID: 1A49C7064E060EEE
6 changed files with 19 additions and 20 deletions

View File

@ -24,7 +24,7 @@ struct AccountView: View {
if let error = model.currentError { if let error = model.currentError {
self.errorHandling.handle(error: error) self.errorHandling.handle(error: error)
} else { } else {
self.errorHandling.handle(error: AppError.genericError("")) self.errorHandling.handle(error: AppError.genericError())
} }
model.hasError = false model.hasError = false
} }

View File

@ -101,13 +101,13 @@ extension UserDefaultsError: LocalizedError {
enum LocalStoreError: Error { enum LocalStoreError: Error {
case couldNotSaveContext case couldNotSaveContext
case couldNotFetchCollections case couldNotFetchCollections
case couldNotFetchPosts(String) case couldNotFetchPosts(String = "")
case couldNotPurgePublishedPosts case couldNotPurgePublishedPosts
case couldNotPurgeCollections case couldNotPurgeCollections
case couldNotLoadStore(String) case couldNotLoadStore(String)
case couldNotMigrateStore(String) case couldNotMigrateStore(String)
case couldNotDeleteStoreAfterMigration(String) case couldNotDeleteStoreAfterMigration(String)
case genericError(String) case genericError(String = "")
} }
extension LocalStoreError: LocalizedError { extension LocalStoreError: LocalizedError {
@ -148,7 +148,7 @@ extension LocalStoreError: LocalizedError {
enum AppError: Error { enum AppError: Error {
case couldNotGetLoggedInClient case couldNotGetLoggedInClient
case couldNotGetPostId case couldNotGetPostId
case genericError(String) case genericError(String = "")
} }
extension AppError: LocalizedError { extension AppError: LocalizedError {

View File

@ -39,7 +39,7 @@ extension WriteFreelyModel {
var secItem: CFTypeRef? var secItem: CFTypeRef?
let status = SecItemCopyMatching(query as CFDictionary, &secItem) let status = SecItemCopyMatching(query as CFDictionary, &secItem)
guard status != errSecItemNotFound else { guard status != errSecItemNotFound else {
return nil throw KeychainError.couldNotFetchAccessToken
} }
guard status == errSecSuccess else { guard status == errSecSuccess else {
throw KeychainError.couldNotFetchAccessToken throw KeychainError.couldNotFetchAccessToken
@ -47,7 +47,7 @@ extension WriteFreelyModel {
guard let existingSecItem = secItem as? [String: Any], guard let existingSecItem = secItem as? [String: Any],
let tokenData = existingSecItem[kSecValueData as String] as? Data, let tokenData = existingSecItem[kSecValueData as String] as? Data,
let token = String(data: tokenData, encoding: .utf8) else { let token = String(data: tokenData, encoding: .utf8) else {
return nil throw KeychainError.couldNotFetchAccessToken
} }
return token return token
} }

View File

@ -87,6 +87,7 @@ final class WriteFreelyModel: ObservableObject {
self.fetchUserPosts() self.fetchUserPosts()
} catch { } catch {
self.currentError = KeychainError.couldNotFetchAccessToken self.currentError = KeychainError.couldNotFetchAccessToken
return
} }
} }
} }

View File

@ -59,21 +59,19 @@ struct ContentView: View {
Text("Select a post, or create a new local draft.") Text("Select a post, or create a new local draft.")
.foregroundColor(.secondary) .foregroundColor(.secondary)
}
EmptyView() .environmentObject(model)
.onChange(of: model.hasError) { value in .onChange(of: model.hasError) { value in
if value { if value {
if let error = model.currentError { if let error = model.currentError {
self.errorHandling.handle(error: error) self.errorHandling.handle(error: error)
} else { } else {
self.errorHandling.handle(error: AppError.genericError("")) self.errorHandling.handle(error: AppError.genericError())
} }
model.hasError = false model.hasError = false
} }
} }
} }
.environmentObject(model)
}
} }
struct ContentView_Previews: PreviewProvider { struct ContentView_Previews: PreviewProvider {

View File

@ -133,7 +133,7 @@ struct PostListView: View {
if let error = model.currentError { if let error = model.currentError {
self.errorHandling.handle(error: error) self.errorHandling.handle(error: error)
} else { } else {
self.errorHandling.handle(error: AppError.genericError("")) self.errorHandling.handle(error: AppError.genericError())
} }
model.hasError = false model.hasError = false
} }
@ -165,7 +165,7 @@ struct PostListView: View {
if let error = model.currentError { if let error = model.currentError {
self.errorHandling.handle(error: error) self.errorHandling.handle(error: error)
} else { } else {
self.errorHandling.handle(error: AppError.genericError) self.errorHandling.handle(error: AppError.genericError())
} }
model.hasError = false model.hasError = false
} }