Skip to content

MOBILE-197: Send data-only payload in WebView sync onError#736

Merged
justSmK merged 3 commits into
developfrom
feature/MOBILE-197-unify-webview-onerror-payload
Jul 16, 2026
Merged

MOBILE-197: Send data-only payload in WebView sync onError#736
justSmK merged 3 commits into
developfrom
feature/MOBILE-197-unify-webview-onerror-payload

Conversation

@justSmK

@justSmK justSmK commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

The WebView JS-bridge onError for mindbox("sync", ...) delivered the error double-wrapped: {"error":"<JSON string>"} around a {type, data} envelope, while onValidationError gets the data contents 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 public toJson() 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.

justSmK added 2 commits July 15, 2026 15:56
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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 WebViewSyncOperationException plus MindboxError.toWebViewDataJson() to generate iOS-style data-only JSON for sync-operation errors.
  • Updates MindboxWebViewOperationExecutor to throw WebViewSyncOperationException on sync-operation failures.
  • Updates WebViewInappViewHolder to 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()

@justSmK justSmK Jul 15, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@justSmK
justSmK merged commit f3c0e92 into develop Jul 16, 2026
7 checks passed
@justSmK
justSmK deleted the feature/MOBILE-197-unify-webview-onerror-payload branch July 16, 2026 08:14
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.

3 participants