Added error message to Error enums

sync2
Laurent 12 months ago
parent 1ef5725029
commit b9a5e7c482
  1. 13
      LeStorage/ApiCallCollection.swift
  2. 2
      LeStorage/Services.swift
  3. 18
      LeStorage/Store.swift
  4. 6
      LeStorage/StoredCollection.swift
  5. 25
      LeStorage/Utils/Errors.swift
  6. 9
      LeStorage/Utils/FileUtils.swift
  7. 11
      LeStorage/Utils/KeychainStore.swift

@ -19,8 +19,15 @@ protocol SomeCallCollection {
}
enum ApiCallError: Error {
case cantCreateCall
enum ApiCallError: Error, LocalizedError {
case encodingError(id: String, type: String)
var errorDescription: String? {
switch self {
case .encodingError(let id, let type):
return "Can't encode instance \(type) with id: \(id)"
}
}
}
/// ApiCallCollection is an object communicating with a server to synchronize data managed locally
@ -236,7 +243,7 @@ actor ApiCallCollection<T: Storable>: SomeCallCollection {
return ApiCall(method: method, dataId: instance.stringId, body: jsonString)
} catch {
StoreCenter.main.log(message: "call could not be created for \(T.resourceName()): \(error.localizedDescription)")
throw ApiCallError.cantCreateCall
throw ApiCallError.encodingError(id: instance.stringId, type: T.resourceName())
}
}

@ -436,7 +436,7 @@ public class Services {
/// - password: the account's password
public func deleteAccount() async throws {
guard let userId = StoreCenter.main.userId else {
throw ServiceError.missingUserId
throw StoreError.missingUserId
}
let path = "users/\(userId)/"
let deleteAccount = ServiceCall(path: path, method: .delete, requiresToken: true)

@ -8,13 +8,25 @@
import Foundation
import UIKit
public enum StoreError: Error {
public enum StoreError: Error, LocalizedError {
case missingService
case missingUserId
case unexpectedCollectionType(name: String)
case apiCallCollectionNotRegistered(type: String)
case collectionNotRegistered(type: String)
case cannotSyncCollection(name: String)
public var errorDescription: String? {
switch self {
case .missingService:
return "Services instance is nil"
case .missingUserId:
return "The user id is missing"
case .collectionNotRegistered(let type):
return "The collection \(type) is not registered"
case .cannotSyncCollection(let name):
return "Tries to load the collection \(name) from the server while it's not authorized"
}
}
}
public struct StoreIdentifier {

@ -7,12 +7,6 @@
import Foundation
enum StoredCollectionError: Error {
case unmanagedHTTPMethod(method: String)
case missingApiCallCollection
case missingInstance
}
protocol CollectionHolder {
associatedtype Item

@ -20,14 +20,33 @@ public class ErrorUtils {
}
public enum ServiceError: Error {
public enum ServiceError: Error, LocalizedError {
case urlCreationError(url: String)
case cantConvertToUUID(id: String)
case missingUserName
case missingUserId
case responseError(response: String)
public var errorDescription: String? {
switch self {
case .urlCreationError(let url):
return "Can't create URL from \(url)"
case .cantConvertToUUID(let id):
return "Cant convert \(id) to UUID"
case .missingUserName:
return "There is no userName defined in the Settings"
case .responseError(let response):
return "The server returned an error: \(response)"
}
}
}
public enum UUIDError: Error {
public enum UUIDError: Error, LocalizedError {
case cantConvertString(string: String)
public var errorDescription: String? {
switch self {
case .cantConvertString(let string):
return "cant convert string to UUID: \(string)"
}
}
}

@ -7,8 +7,15 @@
import Foundation
enum FileError : Error {
enum FileError: Error, LocalizedError {
case documentDirectoryNotFound
var errorDescription: String? {
switch self {
case .documentDirectoryNotFound:
return "The document directory has not been found"
}
}
}
class FileUtils {

@ -11,6 +11,17 @@ enum KeychainError: Error {
case keychainItemNotFound(serverId: String)
case unexpectedPasswordData
case unhandledError(status: OSStatus)
var errorDescription: String? {
switch self {
case .keychainItemNotFound(let serverId):
return "The keychainItem was not found: \(serverId)"
case .unexpectedPasswordData:
return "Keychain error: The data could not be converted to string"
case .unhandledError(let status):
return "Keychain error: Unmanaged status: \(status)"
}
}
}
class KeychainStore {

Loading…
Cancel
Save