Auth0.swift icon indicating copy to clipboard operation
Auth0.swift copied to clipboard

isNetworkError does not report case where Wifi + Mobile Data is off

Open lordzsolt opened this issue 1 year ago • 1 comments

Checklist

  • [X] The issue can be reproduced in the Auth0.swift sample app (or N/A).
  • [X] I have looked into the Readme, Examples, and FAQ and have not found a suitable solution or answer.
  • [X] I have looked into the API documentation and have not found a suitable solution or answer.
  • [X] I have searched the issues and have not found a suitable solution or answer.
  • [X] I have searched the Auth0 Community forums and have not found a suitable solution or answer.
  • [X] I agree to the terms within the Auth0 Code of Conduct.

Description

When I turn off Wifi + Mobile Data, and I call oauth/token through Auth0.swift, I receive the following error:

Unhandled error happened: The credentials renewal failed. CAUSE: Unable to complete the operation. CAUSE: Error Domain=NSURLErrorDomain Code=-1020 "A data connection is not currently allowed."

AuthenticationError.isNetworkError will report this as false, because:

Error code -1020 is equivalent to .dataNotAllowed which is not in the list of networkErrorCodes.


Interestingly, if I put the phone into airplane mode, I receive .notConnectedToInternet and this is reported as network error... 🤯


What is the intended purpose of isNetworkError?

  • I was intending to use it to distinguish between unknown errors and network errors.

Reproduction

  1. Log in with a user on a physical device
  2. Turn off Mobile Data + Wifi
  3. Call CredentialsManager.credentials(minTTL:) with a token that triggers the oauth/token endpoint
  4. Notice the returned error, and isNetworkError being false

Additional context

No response

Auth0.swift version

2.5.0

Platform

iOS

Platform version(s)

16.1.1

Xcode version

15.0

Package manager

Cocoapods

lordzsolt avatar Jan 11 '24 12:01 lordzsolt

Hi @lordzsolt, thanks for raising this.

.dataNotAllowed should indeed be on the list of networkErrorCodes. If you raise a PR adding it I'll happily review it.

Widcket avatar Jan 11 '24 14:01 Widcket