From ab051aadf6862229edeb0822dbe08eecb9042463 Mon Sep 17 00:00:00 2001 From: Michael Rebello Date: Wed, 18 Jan 2023 14:58:39 -0800 Subject: [PATCH] Add public initializers for `ConnectError` This allows consumers to create errors in custom implementations and for testing purposes. --- Libraries/Connect/Interfaces/ConnectError.swift | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Libraries/Connect/Interfaces/ConnectError.swift b/Libraries/Connect/Interfaces/ConnectError.swift index 57c8a6b9..e3d68409 100644 --- a/Libraries/Connect/Interfaces/ConnectError.swift +++ b/Libraries/Connect/Interfaces/ConnectError.swift @@ -47,6 +47,16 @@ public struct ConnectError: Swift.Error { } } + public init( + code: Code, message: String?, exception: Error?, details: [Detail], metadata: Headers + ) { + self.code = code + self.message = message + self.exception = exception + self.details = details + self.metadata = metadata + } + /// Error details are sent over the network to clients, which can then work with /// strongly-typed data rather than trying to parse a complex error message. For /// example, you might use details to send a localized error message or retry @@ -62,6 +72,11 @@ public struct ConnectError: Swift.Error { case type = "type" case payload = "value" } + + public init(type: String, payload: Data?) { + self.type = type + self.payload = payload + } } }