Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get underlying error from URLSessionClientError #1293

Closed
asengmany opened this issue Jul 7, 2020 · 4 comments
Closed

Get underlying error from URLSessionClientError #1293

asengmany opened this issue Jul 7, 2020 · 4 comments

Comments

@asengmany
Copy link

Hi, I'm trying to handle errors when internet connection is off
I was wondering how can we get the localized description of the underlying error from func networkTransport(_ networkTransport: HTTPNetworkTransport, receivedError error: Error, for request: URLRequest, response: URLResponse?, continueHandler: @escaping (HTTPNetworkTransport.ContinueAction) -> Void)

Because when printing the error.localizedDescription from this delegate function we get the message The operation couldn’t be completed. (Apollo.URLSessionClient.URLSessionClientError error 2.)" which is not a great message to display to users.

@designatednerd
Copy link
Contributor

Ah i need to add some LocalizedError support to that in general, but you should be able to switch on the various cases of URLSessionClientError to figure out which error you're getting there.

@designatednerd
Copy link
Contributor

(Note that even with the URLSessionClientError getting error descriptions, I'd still recommend switching on the error you get, because each of the error types comes with additional details, like an exact error returned by the system and/or data returned from your server)

@asengmany
Copy link
Author

Thank you, by switching on the error I got what I wanted :).

switch error {
case URLSessionClient.URLSessionClientError.networkError(let data, let response, let underlying):
   continueHandler(.fail(underlying))
default:
   continueHandler(.fail(error))
}

@designatednerd
Copy link
Contributor

Cool - I'll close this out then, and the updated strings will ship with the next release. Thanks for pointing this out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants