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 {
self.errorHandling.handle(error: error)
} else {
self.errorHandling.handle(error: AppError.genericError(""))
self.errorHandling.handle(error: AppError.genericError())
}
model.hasError = false
}

View File

@ -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 {

View File

@ -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
}

View File

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

View File

@ -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
}
}
}
}

View File

@ -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
}