From d4bd9ce971fafa4c823b9deec0b6b5e10960a6be Mon Sep 17 00:00:00 2001 From: Laurent Date: Wed, 5 Jun 2024 15:07:55 +0200 Subject: [PATCH] Provides util method to get a proper error message + refactoring --- LeStorage/Services.swift | 7 ------- LeStorage/Utils/Errors.swift | 20 ++++++++++++++++++++ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/LeStorage/Services.swift b/LeStorage/Services.swift index 139bf1b..41b2113 100644 --- a/LeStorage/Services.swift +++ b/LeStorage/Services.swift @@ -14,13 +14,6 @@ public enum HTTPMethod: String, CaseIterable, Codable { case delete = "DELETE" } -public enum ServiceError: Error { - case urlCreationError(url: String) - case cantConvertToUUID(id: String) - case missingUserName - case responseError(response: String) -} - fileprivate enum ServiceConf: String { case createAccount = "users/" case requestToken = "api-token-auth/" diff --git a/LeStorage/Utils/Errors.swift b/LeStorage/Utils/Errors.swift index 524c779..ce91a31 100644 --- a/LeStorage/Utils/Errors.swift +++ b/LeStorage/Utils/Errors.swift @@ -7,6 +7,26 @@ 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 { + case urlCreationError(url: String) + case cantConvertToUUID(id: String) + case missingUserName + case responseError(response: String) +} + public enum UUIDError: Error { case cantConvertString(string: String) }