-
Notifications
You must be signed in to change notification settings - Fork 6
MOBILE-197: Send data-only payload in WebView sync onError #736
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
justSmK
merged 3 commits into
develop
from
feature/MOBILE-197-unify-webview-onerror-payload
Jul 16, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
...c/main/java/cloud/mindbox/mobile_sdk/inapp/presentation/view/WebViewSyncOperationError.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| package cloud.mindbox.mobile_sdk.inapp.presentation.view | ||
|
|
||
| import cloud.mindbox.mobile_sdk.models.MindboxError | ||
| import com.google.gson.Gson | ||
| import com.google.gson.JsonObject | ||
|
|
||
| internal class WebViewSyncOperationException(val payloadJson: String) : Exception(payloadJson) | ||
|
|
||
| /** | ||
| * Data-only JSON without the `{type, data}` envelope — the WebView JS-bridge `onError` | ||
| * contract shared with iOS: string `httpStatusCode`, no transport `statusCode`. | ||
| * `toJson()` must keep the envelope: RN/Flutter wrappers dispatch on it. | ||
| * | ||
| * Serialized via `JsonElement.toString()`, not `gson.toJson`: the SDK gson has | ||
| * htmlSafe enabled and would escape `<`/`&`/`'`, while iOS `JSONEncoder` does not. | ||
| */ | ||
| internal fun MindboxError.toWebViewDataJson(gson: Gson): String { | ||
| val data = JsonObject() | ||
| when (this) { | ||
| is MindboxError.Validation -> { | ||
| data.addProperty("status", status) | ||
| data.add("validationMessages", gson.toJsonTree(validationMessages)) | ||
| } | ||
|
|
||
| is MindboxError.Protocol -> | ||
| data.addServerErrorFields(status, errorMessage, errorId, httpStatusCode) | ||
|
|
||
| is MindboxError.InternalServer -> | ||
| data.addServerErrorFields(status, errorMessage, errorId, httpStatusCode) | ||
|
|
||
| is MindboxError.UnknownServer -> { | ||
| status?.let { data.addProperty("status", it) } | ||
| errorMessage?.let { data.addProperty("errorMessage", it) } | ||
| errorId?.let { data.addProperty("errorId", it) } | ||
| data.addProperty("httpStatusCode", httpStatusCode?.toString() ?: "null") | ||
| } | ||
|
|
||
| is MindboxError.Unknown -> { | ||
| data.addProperty("errorKey", "unknown") | ||
| data.addProperty("errorName", throwable?.javaClass?.canonicalName ?: "") | ||
| data.addProperty("errorMessage", throwable?.localizedMessage ?: "") | ||
| } | ||
| } | ||
| return data.toString() | ||
| } | ||
|
|
||
| private fun JsonObject.addServerErrorFields( | ||
| status: String, | ||
| errorMessage: String?, | ||
| errorId: String?, | ||
| httpStatusCode: Int?, | ||
| ) { | ||
| addProperty("status", status) | ||
| errorMessage?.let { addProperty("errorMessage", it) } | ||
| addProperty("errorId", errorId ?: "") | ||
| addProperty("httpStatusCode", httpStatusCode?.toString() ?: "null") | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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.