MOBILE-197: Send data-only payload in WebView sync onError#736
Conversation
Drop both wrappers: the {type, data} envelope from toJson and the
{"error": ...} double serialization in sendErrorResponse. The payload
format is shared with iOS: string httpStatusCode, no transport
statusCode. toJson() is unchanged - public API used by wrapper SDKs.
There was a problem hiding this comment.
Pull request overview
This PR updates the Android WebView JS-bridge error contract for mindbox("sync", ...) so that sync-operation onError returns a data-only JSON payload matching iOS (instead of the previously double-wrapped {"error":"<json>"} form), reducing per-platform parsing differences in popup JS.
Changes:
- Introduces
WebViewSyncOperationExceptionplusMindboxError.toWebViewDataJson()to generate iOS-style data-only JSON for sync-operation errors. - Updates
MindboxWebViewOperationExecutorto throwWebViewSyncOperationExceptionon sync-operation failures. - Updates
WebViewInappViewHolderto pass through sync-operation error payloads directly, and expands unit tests to validate payload shapes across error types.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| sdk/src/test/java/cloud/mindbox/mobile_sdk/inapp/presentation/view/WebViewOperationExecutorTest.kt | Refactors sync-operation error test helper and adds coverage for new data-only payload formats across MindboxError variants. |
| sdk/src/main/java/cloud/mindbox/mobile_sdk/inapp/presentation/view/WebViewSyncOperationError.kt | Adds the new sync-operation exception type and the data-only JSON serializer for MindboxError. |
| sdk/src/main/java/cloud/mindbox/mobile_sdk/inapp/presentation/view/WebViewOperationExecutor.kt | Switches sync-operation error propagation from IllegalStateException(error.toJson()) to WebViewSyncOperationException(toWebViewDataJson(...)). |
| sdk/src/main/java/cloud/mindbox/mobile_sdk/inapp/presentation/view/WebViewInappViewHolder.kt | Updates bridge error response building to avoid wrapping sync-operation errors in {"error":"…"}. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| data.addProperty("errorMessage", throwable?.localizedMessage ?: "") | ||
| } | ||
| } | ||
| return data.toString() |
There was a problem hiding this comment.
gson.toJson(data) wouldn't produce the same payload: the injected Gson is built without disableHtmlEscaping(), so it would emit \u003c-style escapes for <, &, ' etc. in errorMessage. This method's contract is byte-parity with iOS JSONEncoder, which doesn't HTML-escape, so JsonElement.toString() (htmlSafe off) is intentional.
The injected gson has htmlSafe enabled and would emit \u003c-style escapes, diverging from iOS JSONEncoder output.
The WebView JS-bridge
onErrorformindbox("sync", ...)delivered the error double-wrapped:{"error":"<JSON string>"}around a{type, data}envelope, whileonValidationErrorgets thedatacontents directly — and iOS wrapped it differently, so popup JS needed per-platform parsing. Sync-operation errors now carry an iOS-format data-only JSON (WebViewSyncOperationException+MindboxError.toWebViewDataJson()); all other bridge errors keep{"error":"…"}, and publictoJson()is untouched since RN/Flutter wrappers dispatch on the{type, data}envelope. Mirrored in mindbox-cloud/ios-sdk#738 — both must release in the same window since this is a breaking change of the popup-JS contract.