From acda3cf69c95970e7e06b0f8ee654697c317c586 Mon Sep 17 00:00:00 2001 From: Michael Rebello Date: Mon, 23 Dec 2024 09:32:15 -0800 Subject: [PATCH 1/2] Use `unavailable` `ConnectError` when URLSession is offline Resolves https://github.com/connectrpc/connect-swift/issues/325. Signed-off-by: Michael Rebello --- .../Implementation/Clients/URLSessionHTTPClient.swift | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Libraries/Connect/Public/Implementation/Clients/URLSessionHTTPClient.swift b/Libraries/Connect/Public/Implementation/Clients/URLSessionHTTPClient.swift index f045732d..f535d60a 100644 --- a/Libraries/Connect/Public/Implementation/Clients/URLSessionHTTPClient.swift +++ b/Libraries/Connect/Public/Implementation/Clients/URLSessionHTTPClient.swift @@ -207,6 +207,15 @@ extension Code { return .deadlineExceeded case URLError.unsupportedURL.rawValue: return .unimplemented + case NSURLErrorCannotConnectToHost, + NSURLErrorCannotFindHost, + NSURLErrorDataNotAllowed, + NSURLErrorInternationalRoamingOff, + NSURLErrorNetworkConnectionLost, + NSURLErrorNotConnectedToInternet, + NSURLErrorSecureConnectionFailed, + NSURLErrorTimedOut: + return .unavailable case ...100: // URLSession can return errors in this range return .unknown default: From 239fc51e77a9b12f113da4d2387402d085789d42 Mon Sep 17 00:00:00 2001 From: Michael Rebello Date: Mon, 23 Dec 2024 11:17:46 -0800 Subject: [PATCH 2/2] fixup Signed-off-by: Michael Rebello --- .../Public/Implementation/Clients/URLSessionHTTPClient.swift | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Libraries/Connect/Public/Implementation/Clients/URLSessionHTTPClient.swift b/Libraries/Connect/Public/Implementation/Clients/URLSessionHTTPClient.swift index f535d60a..3d4ef113 100644 --- a/Libraries/Connect/Public/Implementation/Clients/URLSessionHTTPClient.swift +++ b/Libraries/Connect/Public/Implementation/Clients/URLSessionHTTPClient.swift @@ -203,7 +203,7 @@ extension Code { return .canceled case URLError.badURL.rawValue: return .invalidArgument - case URLError.timedOut.rawValue: + case URLError.timedOut.rawValue, NSURLErrorTimedOut: return .deadlineExceeded case URLError.unsupportedURL.rawValue: return .unimplemented @@ -213,8 +213,7 @@ extension Code { NSURLErrorInternationalRoamingOff, NSURLErrorNetworkConnectionLost, NSURLErrorNotConnectedToInternet, - NSURLErrorSecureConnectionFailed, - NSURLErrorTimedOut: + NSURLErrorSecureConnectionFailed: return .unavailable case ...100: // URLSession can return errors in this range return .unknown