Expose NetworkErrorException when request fails due to networking #235
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Changes
Currently, all network requests performed by OkHttp will either fail or succeed.
onSuccess
is called and the requests have an HTTP status code set (e.g. 200, 401, 500, etc).onFailure
is called with anIOException
instance. This scenario means network error (e.g. invalid host, timeout, etc).Normally one doesn't need to capture this scenario as OkHttp is known for retrying the request a few times before reporting it as a failure. And additionally the Android SDK provides methods to check for connectivity before you perform a request. But in case you want a more granular control, this PR ensures that the exception is not treated as "another Auth0 error" along with the API errors (success branch above ☝️) and now has its own dedicated exception thrown. (I don't really like the idea of adding a new exception class, but here we go..)
Now users after calling
request.execute()
orrequest.start({callback})
can capture thatAuth0Exception
and ask if it's an instance ofNetworkErrorException
class by using the helper methodisNetworkError()
.References
Closes #234.
Testing
This change adds unit test coverage
This change adds integration test coverage
This change has been tested on the latest version of the platform/language or why not
Checklist
I have read the Auth0 general contribution guidelines
I have read the Auth0 Code of Conduct
All existing and new tests complete without errors