Skip to content

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

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

MOBILE-197: Send data-only payload in WebView sync onError#738
justSmK merged 4 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 wrapped in a {type, data} envelope, while onValidationError gets the data contents directly — and Android wrapped it differently, so popup JS needed per-platform parsing. The failure branch now sends a data-only JSON via a new internal createDataJSON(); public createJSON() is byte-identical since RN/Flutter wrappers dispatch on the {type, data} envelope. Mirrored in mindbox-cloud/android-sdk#736 — 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
The JS-bridge onError contract must match onValidationError: the
contents of data directly, without the {type, data} envelope.
createJSON() is unchanged - public API used by wrapper SDKs.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 WebView JS-bridge contract for mindbox("sync", ...) error handling so that the onError payload is a data-only JSON object (matching onValidationError and aligning with Android), removing the previous {type, data} envelope for this path.

Changes:

  • Added MindboxError.createDataJSON() to encode only the inner data payload, while keeping createJSON()’s envelope for existing consumers (e.g., RN/Flutter dispatch).
  • Updated TransparentView.makeSyncOperationResponse to send createDataJSON() on the failure (.error) branch.
  • Expanded unit tests to assert that sync-operation error payloads contain only the data contents (no type / data keys).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
MindboxTests/InApp/Tests/TransparentViewSyncOperationResponseTests.swift Adds assertions that WebView sync onError payloads are data-only across multiple error types.
Mindbox/Model/MindboxError/MindboxError.swift Introduces createDataJSON() and refactors error JSON construction to support both envelope and data-only encodings.
Mindbox/InAppMessages/Presentation/Views/WebView/TransparentView.swift Switches sync-operation failure payload from createJSON() to createDataJSON().

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +146 to +150
func convertDataToString() -> String {
guard
let errorData = try? JSONEncoder().encode(data),
let errorString = String(data: errorData, encoding: .utf8) else {
return #"{"errorMessage":"Unable to convert Data to JSON"}"#

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.

Pre-existing on develop, but fair — fixed in 172f622: the fallback is now compact valid JSON with correct key names.

Comment on lines +135 to +139
@Test("Protocol error payload is the data contents: status, errorMessage, httpStatusCode, errorId")
func protocolError_payloadIsDataContentsOnly() throws {
let pe = ProtocolError(status: .protocolError, errorMessage: "Operation Test not found", httpStatusCode: 400, errorId: "error-id-1")
let outgoing = TransparentView.makeSyncOperationResponse(
result: .failure(.protocolError(pe)),

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.

Added both cases in 7c6e52a: invalidResponse (HTTPURLResponse 403) and unknown (NSError with localized description).

@github-actions

github-actions Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor
TestsPassed ✅SkippedFailedTime ⏱
Unit tests report1329 ran1329 ✅9m 7s 760ms

justSmK added 2 commits July 15, 2026 21:40
The convertToString() fallback had unquoted keys, trailing commas and
misspelled errroKey/errroName — unparseable by any JS consumer. Flagged
by Copilot on the PR; pre-existing, but it belongs to this contract.
@justSmK
justSmK merged commit 49811c6 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