MOBILE-197: Send data-only payload in WebView sync onError#738
Conversation
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.
There was a problem hiding this comment.
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 innerdatapayload, while keepingcreateJSON()’s envelope for existing consumers (e.g., RN/Flutter dispatch). - Updated
TransparentView.makeSyncOperationResponseto sendcreateDataJSON()on the failure (.error) branch. - Expanded unit tests to assert that sync-operation error payloads contain only the data contents (no
type/datakeys).
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.
| 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"}"# |
There was a problem hiding this comment.
Pre-existing on develop, but fair — fixed in 172f622: the fallback is now compact valid JSON with correct key names.
| @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)), |
There was a problem hiding this comment.
Added both cases in 7c6e52a: invalidResponse (HTTPURLResponse 403) and unknown (NSError with localized description).
|
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.
The WebView JS-bridge
onErrorformindbox("sync", ...)delivered the error wrapped in a{type, data}envelope, whileonValidationErrorgets thedatacontents 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 internalcreateDataJSON(); publiccreateJSON()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.