Skip to content

[SDK-716] Typed failure results for online API callbacks - #1120

Open
franco-zalamena-iterable wants to merge 8 commits into
fix/SDK-875-offline-runner-hardeningfrom
feature/SDK-716a-typed-failures
Open

franco-zalamena-iterable wants to merge 8 commits into
fix/SDK-875-offline-runner-hardeningfrom
feature/SDK-716a-typed-failures

Conversation

@franco-zalamena-iterable

@franco-zalamena-iterable franco-zalamena-iterable commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

📝 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 IterableResponseObject with the Category enum (NETWORK, SERVER_ERROR, RATE_LIMITED, AUTH, CLIENT_ERROR, SDK) and the Failure, RetriableFailure and TerminalFailure classes. A Failure has a @Nullable getReason(), a nullable HTTP status, the response JSON, the iterableCode from the body and the category. TerminalFailure also has isRetriesExhausted(), 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.

FailureHandler gets a default onFailureResult(Failure) that calls onFailure(String, JSONObject) with the same arguments. It's additive, so lambdas and Kotlin method references like handler::onFailure keep compiling, and FailureHandlerReferenceTest covers that. Integrators override onFailureResult only if they want the typed failure.

Online failures map like this:

Response Category Type
Connection error or timeout NETWORK Terminal
5xx and unexpected statuses (3xx, 600+) SERVER_ERROR Terminal
429 RATE_LIMITED Terminal
401 with a JWT error code AUTH Retriable
Other 4xx, including a 401 for an invalid API key CLIENT_ERROR Terminal
A failed 2xx or no usable response SDK Terminal

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:testReleaseUnitTest gives 888 tests, 21 skipped and 0 failures on both. Checkstyle, lint and the androidTest compile are green. IterableRequestTaskFailureTest runs 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 and IterableResponseObject tests cover the mapping table above.

🧾 Changelog

Added two entries under ### Added in CHANGELOG.md, one for the new failure types and onFailureResult, and one for the online delivery.

Open points

  • A handler passed to setEmail or setUserId still gets only the 2-arg onFailure(String, JSONObject) call, including for the push registration those calls start. This is fixed in a follow-up PR on this ticket.
  • A JWT 401 is reported as 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.
  • If app tests mock FailureHandler with Mockito, verify, doAnswer and doNothing on onFailure(String, JSONObject) won't see the call anymore, since Mockito stubs default methods. They need to verify or stub onFailureResult instead, or use a spy. This is in the CHANGELOG.
  • The typed callback fires once per request with the final result, so online a RetriableFailure only 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

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>
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.

1 participant