From 51c28754095599ab1104b8f012e158a738ca4618 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Portela=20Afonso?= Date: Mon, 17 Oct 2022 16:01:35 +0100 Subject: [PATCH 1/3] feat(error): FabricError protocol and generic error --- Sources/YData/Core/FabricError.swift | 47 ++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 Sources/YData/Core/FabricError.swift diff --git a/Sources/YData/Core/FabricError.swift b/Sources/YData/Core/FabricError.swift new file mode 100644 index 0000000..ff2ccc9 --- /dev/null +++ b/Sources/YData/Core/FabricError.swift @@ -0,0 +1,47 @@ +import Foundation + +public protocol FabricError: Error { + var context: [AnyHashable: Any]? { get } + var description: String { get } + var httpCode: Int? { get } + var name: String { get } + var returnValue: Int { get } +} + +extension FabricError { + var name: String { "\(Self.self)" } +} + + +class GenericFabricError: FabricError { + var context: [AnyHashable: Any]? + var description: String + var httpCode: Int? + var _name: String? // swiftlint:disable:this identifier_name + var returnValue: Int + + var name: String { + get { + _name ?? "\(Self.self)" + } + + set { + _name = newValue + } + } + + init( + context: [AnyHashable: Any]? = nil, + description: String, + httpCode: Int? = nil, + name: String? = nil, + returnValue: Int + ) { + self.context = context + self.description = description + self.httpCode = httpCode + self._name = name + self.returnValue = returnValue + } +} + From b38160257f3c9681eefefaafb90c156982b91cf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Portela=20Afonso?= Date: Mon, 17 Oct 2022 23:06:46 +0100 Subject: [PATCH 2/3] fix class access --- Sources/YData/Core/Error/FabricError.swift | 13 ++++++++++ .../GenericFabricError.swift} | 26 +++++-------------- 2 files changed, 19 insertions(+), 20 deletions(-) create mode 100644 Sources/YData/Core/Error/FabricError.swift rename Sources/YData/Core/{FabricError.swift => Error/GenericFabricError.swift} (52%) diff --git a/Sources/YData/Core/Error/FabricError.swift b/Sources/YData/Core/Error/FabricError.swift new file mode 100644 index 0000000..0554a83 --- /dev/null +++ b/Sources/YData/Core/Error/FabricError.swift @@ -0,0 +1,13 @@ +import Foundation + +public protocol FabricError: Error { + var context: [AnyHashable: Any]? { get } + var description: String { get } + var httpCode: Int? { get } + var name: String { get } + var returnValue: Int { get } +} + +public extension FabricError { + var name: String { "\(Self.self)" } +} diff --git a/Sources/YData/Core/FabricError.swift b/Sources/YData/Core/Error/GenericFabricError.swift similarity index 52% rename from Sources/YData/Core/FabricError.swift rename to Sources/YData/Core/Error/GenericFabricError.swift index ff2ccc9..95d6ba1 100644 --- a/Sources/YData/Core/FabricError.swift +++ b/Sources/YData/Core/Error/GenericFabricError.swift @@ -1,26 +1,13 @@ import Foundation -public protocol FabricError: Error { - var context: [AnyHashable: Any]? { get } - var description: String { get } - var httpCode: Int? { get } - var name: String { get } - var returnValue: Int { get } -} - -extension FabricError { - var name: String { "\(Self.self)" } -} - - -class GenericFabricError: FabricError { - var context: [AnyHashable: Any]? - var description: String - var httpCode: Int? +public class GenericFabricError: FabricError { + public var context: [AnyHashable: Any]? + public var description: String + public var httpCode: Int? var _name: String? // swiftlint:disable:this identifier_name - var returnValue: Int + public var returnValue: Int - var name: String { + public var name: String { get { _name ?? "\(Self.self)" } @@ -44,4 +31,3 @@ class GenericFabricError: FabricError { self.returnValue = returnValue } } - From 5857a94fbad55ee5f011448eb5835ec2873078e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Portela=20Afonso?= Date: Tue, 18 Oct 2022 15:56:42 +0100 Subject: [PATCH 3/3] convert context to [String:String] --- Sources/YData/Core/Error/FabricError.swift | 4 ++-- Sources/YData/Core/Error/GenericFabricError.swift | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/YData/Core/Error/FabricError.swift b/Sources/YData/Core/Error/FabricError.swift index 0554a83..c39a10a 100644 --- a/Sources/YData/Core/Error/FabricError.swift +++ b/Sources/YData/Core/Error/FabricError.swift @@ -1,7 +1,7 @@ import Foundation -public protocol FabricError: Error { - var context: [AnyHashable: Any]? { get } +public protocol FabricError: Error, Codable { + var context: [String: String]? { get } var description: String { get } var httpCode: Int? { get } var name: String { get } diff --git a/Sources/YData/Core/Error/GenericFabricError.swift b/Sources/YData/Core/Error/GenericFabricError.swift index 95d6ba1..976b3cc 100644 --- a/Sources/YData/Core/Error/GenericFabricError.swift +++ b/Sources/YData/Core/Error/GenericFabricError.swift @@ -1,7 +1,7 @@ import Foundation public class GenericFabricError: FabricError { - public var context: [AnyHashable: Any]? + public var context: [String: String]? public var description: String public var httpCode: Int? var _name: String? // swiftlint:disable:this identifier_name @@ -18,7 +18,7 @@ public class GenericFabricError: FabricError { } init( - context: [AnyHashable: Any]? = nil, + context: [String: String]? = nil, description: String, httpCode: Int? = nil, name: String? = nil,