From 082000873105c91819fe3a82e8144d6525fb805d Mon Sep 17 00:00:00 2001 From: Michael Rebello Date: Tue, 31 Dec 2024 11:59:23 -0800 Subject: [PATCH] Add `LocalizedError` conformance to `ConnectError` (#327) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This improves how error messages are surfaced through `ConnectError`. Before: ``` (lldb) po response.error?.localizedDescription ▿ Optional - some : "The operation couldn’t be completed. (Connect.ConnectError error 1.)" ``` After: ``` (lldb) po response.error?.localizedDescription ▿ Optional - some : "The Internet connection appears to be offline." ``` Signed-off-by: Michael Rebello --- Libraries/Connect/Public/Interfaces/ConnectError.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Libraries/Connect/Public/Interfaces/ConnectError.swift b/Libraries/Connect/Public/Interfaces/ConnectError.swift index ae36b25..ddbadce 100644 --- a/Libraries/Connect/Public/Interfaces/ConnectError.swift +++ b/Libraries/Connect/Public/Interfaces/ConnectError.swift @@ -111,6 +111,12 @@ extension ConnectError: Decodable { } } +extension ConnectError: LocalizedError { + public var errorDescription: String? { + return self.message ?? self.exception.map { "internal error: \($0.localizedDescription)" } + } +} + extension ConnectError { public static func from( code: Code, headers: Headers?, trailers: Trailers?, source: Data?