diff --git a/Sources/AsyncHTTPClient/FoundationExtensions.swift b/Sources/AsyncHTTPClient/FoundationExtensions.swift index eeff2ad7e..343470fb1 100644 --- a/Sources/AsyncHTTPClient/FoundationExtensions.swift +++ b/Sources/AsyncHTTPClient/FoundationExtensions.swift @@ -21,6 +21,12 @@ import FoundationEssentials import Foundation #endif +extension HTTPClientError: LocalizedError { + public var errorDescription: String? { + self.description + } +} + extension HTTPClient.Cookie { /// The cookie's expiration date. public var expires: Date? { diff --git a/Tests/AsyncHTTPClientTests/FoundationExtensionTests.swift b/Tests/AsyncHTTPClientTests/FoundationExtensionTests.swift index 4ff0d6c26..bfc0c8782 100644 --- a/Tests/AsyncHTTPClientTests/FoundationExtensionTests.swift +++ b/Tests/AsyncHTTPClientTests/FoundationExtensionTests.swift @@ -19,6 +19,21 @@ import Testing @Suite struct FoundationExtensionTests { + @Test + func httpClientErrorLocalizedDescriptionUsesDescription() { + let error = HTTPClientError.cancelled + + #expect(error.localizedDescription == error.description) + } + + @Test + func httpClientErrorLocalizedDescriptionPreservesAssociatedValues() { + let error = HTTPClientError.unsupportedScheme("custom") + + #expect(error.localizedDescription == error.description) + #expect(error.localizedDescription.contains("custom")) + } + @Test(arguments: [ // Format: (input, expected) ("localhost", "localhost"), // Alphanumerics (No encoding needed)