You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
LeStorage/LeStorage/Utils/Errors.swift

61 lines
1.7 KiB

//
// Errors.swift
// LeStorage
//
// Created by Laurent Morvillier on 21/02/2024.
//
import Foundation
public class ErrorUtils {
public static func message(error: Error) -> String {
switch error {
case ServiceError.responseError(let reason):
return reason
default:
return error.localizedDescription
}
}
}
public enum ServiceError: Error, LocalizedError {
case urlCreationError(url: String)
case cantConvertToUUID(id: String)
case missingUserName
case responseError(response: String)
case cantDecodeData(resource: String, method: String, content: 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)"
case .cantDecodeData(let resource, let method, let content):
return "cannot decode data from \(resource), method: \(method): \(content ?? "")"
}
}
}
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)"
}
}
}
public enum LeStorageError: Error {
case cantFindClassFromName(name: String)
case cantAccessCFBundleName
}