Repository navigation
[SDK-716] Typed failure results for online API callbacks - #1120
Open
franco-zalamena-iterable wants to merge 8 commits into
Open
franco-zalamena-iterable wants to merge 8 commits into
franco-zalamena-iterable wants to merge 8 commits into
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…716a-typed-failures Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…716a-typed-failures
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
📝 Summary
Failure handlers of online requests can now get a typed failure that says if the SDK will retry the request and why it failed. Existing handlers keep working unchanged.
🎟️ Jira Ticket: SDK-716
Epic: SDK-454
iOS counterpart: SDK-455
📖 Description
This PR adds
IterableResponseObjectwith theCategoryenum (NETWORK,SERVER_ERROR,RATE_LIMITED,AUTH,CLIENT_ERROR,SDK) and theFailure,RetriableFailureandTerminalFailureclasses. AFailurehas a@Nullable getReason(), a nullable HTTP status, the response JSON, theiterableCodefrom the body and the category.TerminalFailurealso hasisRetriesExhausted(), which is true when the request could have been retried but used all its attempts or the deadline, under the network retry policy or the existing 5xx retries.FailureHandlergets a defaultonFailureResult(Failure)that callsonFailure(String, JSONObject)with the same arguments. It's additive, so lambdas and Kotlin method references likehandler::onFailurekeep compiling, andFailureHandlerReferenceTestcovers that. Integrators overrideonFailureResultonly if they want the typed failure.Online failures map like this:
Each call still gets one callback, on the same thread as before, and handlers that only implement
onFailure(String, JSONObject)get the same reason and JSON. Failures of requests stored by offline mode and failures the SDK detects before sending are unchanged.🧪 How to test?
./gradlew :iterableapi:testDebugUnitTest :iterableapi:testReleaseUnitTestgives 888 tests, 21 skipped and 0 failures on both. Checkstyle, lint and the androidTest compile are green.IterableRequestTaskFailureTestruns every online failure path end to end with a real dispatcher and MockWebServer, for a typed handler and a legacy handler. It checks the type, category, status,iterableCode, exhausted flag and that there is exactly one callback, and it pins the legacy reason and JSON. A separate test runs the request on a background thread and checks the failure is delivered on the main thread. The classifier andIterableResponseObjecttests cover the mapping table above.🧾 Changelog
Added two entries under
### AddedinCHANGELOG.md, one for the new failure types andonFailureResult, and one for the online delivery.Open points
setEmailorsetUserIdstill gets only the 2-argonFailure(String, JSONObject)call, including for the push registration those calls start. This is fixed in a follow-up PR on this ticket.RetriableFailure(AUTH), since the SDK refreshes the token and may re-send the request. The re-send isn't guaranteed until SDK-780, for example while auth retries are paused.FailureHandlerwith Mockito,verify,doAnsweranddoNothingononFailure(String, JSONObject)won't see the call anymore, since Mockito stubs default methods. They need to verify or stubonFailureResultinstead, or use a spy. This is in the CHANGELOG.RetriableFailureonly comes from a JWT 401. Seeing a request as retriable during its retries is for offline requests, and comes with typed delivery for stored tasks in the follow-up PR, after SDK-886.🤖 Generated with Claude Code