diff --git a/Shared/Account/AccountView.swift b/Shared/Account/AccountView.swift index fe22f19..0b54f0e 100644 --- a/Shared/Account/AccountView.swift +++ b/Shared/Account/AccountView.swift @@ -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 } diff --git a/Shared/ErrorHandling/ErrorConstants.swift b/Shared/ErrorHandling/ErrorConstants.swift index 676f299..b412fdb 100644 --- a/Shared/ErrorHandling/ErrorConstants.swift +++ b/Shared/ErrorHandling/ErrorConstants.swift @@ -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 { diff --git a/Shared/Extensions/WriteFreelyModel+Keychain.swift b/Shared/Extensions/WriteFreelyModel+Keychain.swift index 4984675..f6555aa 100644 --- a/Shared/Extensions/WriteFreelyModel+Keychain.swift +++ b/Shared/Extensions/WriteFreelyModel+Keychain.swift @@ -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 } diff --git a/Shared/Models/WriteFreelyModel.swift b/Shared/Models/WriteFreelyModel.swift index 63b9695..617385f 100644 --- a/Shared/Models/WriteFreelyModel.swift +++ b/Shared/Models/WriteFreelyModel.swift @@ -87,6 +87,7 @@ final class WriteFreelyModel: ObservableObject { self.fetchUserPosts() } catch { self.currentError = KeychainError.couldNotFetchAccessToken + return } } } diff --git a/Shared/Navigation/ContentView.swift b/Shared/Navigation/ContentView.swift index ca13ff5..f57a541 100644 --- a/Shared/Navigation/ContentView.swift +++ b/Shared/Navigation/ContentView.swift @@ -59,20 +59,18 @@ struct ContentView: View { Text("Select a post, or create a new local draft.") .foregroundColor(.secondary) - - EmptyView() - .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("")) - } - model.hasError = false - } - } } .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()) + } + model.hasError = false + } + } } } diff --git a/Shared/PostList/PostListView.swift b/Shared/PostList/PostListView.swift index 16e1f45..c1bb662 100644 --- a/Shared/PostList/PostListView.swift +++ b/Shared/PostList/PostListView.swift @@ -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 }