Skip to content

Use ConnectError.unavailable when client is offline#328

Merged
rebello95 merged 4 commits into
mainfrom
network-unavailable
Dec 31, 2024
Merged

Use ConnectError.unavailable when client is offline#328
rebello95 merged 4 commits into
mainfrom
network-unavailable

Conversation

@rebello95

@rebello95 rebello95 commented Dec 23, 2024

Copy link
Copy Markdown
Collaborator

Resolves #325.

When turning the device's wifi off, the following was observed with URLSession:

Before:

▿ Optional<ConnectError>
  ▿ some : ConnectError
    - code : Connect.Code.unknown
    ▿ message : Optional<String>
      - some : "The Internet connection appears to be offline."
    ▿ exception : Optional<Error>
      - some : Error Domain=NSURLErrorDomain Code=-1009 "The Internet connection appears to be offline." 

Based on the discussion in the issue linked above, this PR updates the code to be .unavailable:

▿ Optional<ConnectError>
  ▿ some : ConnectError
    - code : Connect.Code.unavailable
    ▿ message : Optional<String>
      - some : "The Internet connection appears to be offline."
    ▿ exception : Optional<Error>
      - some : Error Domain=NSURLErrorDomain Code=-1009 "The Internet connection appears to be offline." 

The NIO client has also been updated to return the .unavailable status code:

▿ Optional<ConnectError>
  ▿ some : ConnectError
    - code : Connect.Code.unavailable
    ▿ message : Optional<String>
      - some : "client is not connected"
    - exception : nil

Resolves #325.

Signed-off-by: Michael Rebello <me@michaelrebello.com>
@rebello95 rebello95 requested a review from jhump December 23, 2024 17:34
@rebello95 rebello95 changed the title Use unavailable ConnectError when URLSession is offline Use ConnectError.unavailable when URLSession is offline Dec 23, 2024
Signed-off-by: Michael Rebello <me@michaelrebello.com>
@aheze

aheze commented Dec 23, 2024

Copy link
Copy Markdown

Btw does this work for NIOHttpClient?

@rebello95 rebello95 changed the title Use ConnectError.unavailable when URLSession is offline Use ConnectError.unavailable when client is offline Dec 27, 2024
@rebello95

Copy link
Copy Markdown
Collaborator Author

Btw does this work for NIOHttpClient?

I just updated the PR to handle both NIO and URLSession 👍🏽

@rebello95 rebello95 merged commit 20c7871 into main Dec 31, 2024
@rebello95 rebello95 deleted the network-unavailable branch December 31, 2024 19:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No distinct error code for lack of internet access

3 participants