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 {
|
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
|
||||||
}
|
}
|
||||||
|
@ -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 {
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
|
@ -87,6 +87,7 @@ final class WriteFreelyModel: ObservableObject {
|
|||||||
self.fetchUserPosts()
|
self.fetchUserPosts()
|
||||||
} catch {
|
} catch {
|
||||||
self.currentError = KeychainError.couldNotFetchAccessToken
|
self.currentError = KeychainError.couldNotFetchAccessToken
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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 {
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user