-
Notifications
You must be signed in to change notification settings - Fork 17
MOBILE-197: Send data-only payload in WebView sync onError #738
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 4 commits into
develop
from
feature/MOBILE-197-unify-webview-onerror-payload
Jul 16, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
cf7f558
MOBILE-197: Send data-only payload in WebView sync onError
justSmK f26f91d
MOBILE-197: Cover data-only sync error payload for all MindboxError k…
justSmK 172f622
MOBILE-197: Make the error-JSON fallback valid JSON
justSmK 7c6e52a
MOBILE-197: Cover invalidResponse and unknown data-only payloads
justSmK 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
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 |
|---|---|---|
|
|
@@ -118,43 +118,126 @@ struct TransparentViewSyncOperationResponseTests { | |
| } | ||
| } | ||
|
|
||
| // MARK: - Failure (.connectionError) → .error with createJSON payload | ||
| // MARK: - Failure payloads: data contents only, no {type, data} envelope (MOBILE-197) | ||
|
|
||
| @Test("Connection failure becomes .error with MindboxError.createJSON payload") | ||
| func connectionError_becomesError() { | ||
| private func decodedErrorPayload(_ outgoing: BridgeMessage) throws -> [String: Any] { | ||
| #expect(outgoing.type == .error) | ||
| var jsonString: String? | ||
| if case .string(let value) = outgoing.payload { jsonString = value } | ||
| let json = try #require(jsonString, "Expected .string payload, got \(String(describing: outgoing.payload))") | ||
| let data = try #require(json.data(using: .utf8)) | ||
| let object = try #require(try JSONSerialization.jsonObject(with: data) as? [String: Any]) | ||
| #expect(object["type"] == nil, "Payload must not carry the {type, data} envelope") | ||
| #expect(object["data"] == nil, "Payload must not carry the {type, data} envelope") | ||
| return object | ||
| } | ||
|
|
||
| @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)), | ||
|
Comment on lines
+135
to
+139
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added both cases in 7c6e52a: |
||
| action: action, | ||
| id: requestId | ||
| ) | ||
|
|
||
| let payload = try decodedErrorPayload(outgoing) | ||
| #expect(payload["status"] as? String == "ProtocolError") | ||
| #expect(payload["errorMessage"] as? String == "Operation Test not found") | ||
| #expect(payload["httpStatusCode"] as? String == "400") | ||
| #expect(payload["errorId"] as? String == "error-id-1") | ||
| } | ||
|
|
||
| @Test("Server error payload is the data contents with InternalServerError status") | ||
| func serverError_payloadIsDataContentsOnly() throws { | ||
| let pe = ProtocolError(status: .internalServerError, errorMessage: "Something went wrong", httpStatusCode: 500) | ||
| let outgoing = TransparentView.makeSyncOperationResponse( | ||
| result: .failure(.serverError(pe)), | ||
| action: action, | ||
| id: requestId | ||
| ) | ||
|
|
||
| let payload = try decodedErrorPayload(outgoing) | ||
| #expect(payload["status"] as? String == "InternalServerError") | ||
| #expect(payload["errorMessage"] as? String == "Something went wrong") | ||
| #expect(payload["httpStatusCode"] as? String == "500") | ||
| } | ||
|
|
||
| @Test("Connection failure payload is the data contents without the NetworkError envelope") | ||
| func connectionError_payloadIsDataContentsOnly() throws { | ||
| let outgoing = TransparentView.makeSyncOperationResponse( | ||
| result: .failure(.connectionError), | ||
| action: action, | ||
| id: requestId | ||
| ) | ||
|
|
||
| #expect(outgoing.type == .error) | ||
| if case .string(let value) = outgoing.payload { | ||
| #expect(value.contains("NetworkError"), "createJSON for connectionError produces a NetworkError envelope") | ||
| #expect(value.contains("Connection error")) | ||
| } else { | ||
| Issue.record("Expected .string payload") | ||
| } | ||
| let payload = try decodedErrorPayload(outgoing) | ||
| #expect(payload["httpStatusCode"] as? String == "null") | ||
| #expect(payload["errorMessage"] as? String == "Connection error") | ||
| } | ||
|
|
||
| @Test("Validation error payload is the data contents with validationMessages") | ||
| func validationError_payloadIsDataContentsOnly() throws { | ||
| let ve = ValidationError( | ||
| status: .validationError, | ||
| validationMessages: [ValidationMessage(message: "Invalid email", location: "/customer/email")] | ||
| ) | ||
| let outgoing = TransparentView.makeSyncOperationResponse( | ||
| result: .failure(.validationError(ve)), | ||
| action: action, | ||
| id: requestId | ||
| ) | ||
|
|
||
| let payload = try decodedErrorPayload(outgoing) | ||
| #expect(payload["status"] as? String == "ValidationError") | ||
| let messages = try #require(payload["validationMessages"] as? [[String: Any]]) | ||
| #expect(messages.count == 1) | ||
| #expect(messages.first?["message"] as? String == "Invalid email") | ||
| #expect(messages.first?["location"] as? String == "/customer/email") | ||
| } | ||
|
|
||
| // MARK: - Failure (.protocolError) → .error with createJSON payload | ||
| @Test("Internal error payload is the data contents with errorKey") | ||
| func internalError_payloadIsDataContentsOnly() throws { | ||
| let outgoing = TransparentView.makeSyncOperationResponse( | ||
| result: .failure(.internalError(InternalError(errorKey: .parsing, reason: "Broken body"))), | ||
| action: action, | ||
| id: requestId | ||
| ) | ||
|
|
||
| let payload = try decodedErrorPayload(outgoing) | ||
| #expect(payload["errorKey"] as? String == "Error_parsing") | ||
| #expect(payload["errorName"] as? String == "Broken body") | ||
| } | ||
|
|
||
| @Test("Invalid response payload is the data contents with httpStatusCode from the response") | ||
| func invalidResponse_payloadIsDataContentsOnly() throws { | ||
| let url = try #require(URL(string: "https://api.mindbox.ru/v3/operations/sync")) | ||
| let httpResponse = try #require(HTTPURLResponse(url: url, statusCode: 403, httpVersion: nil, headerFields: nil)) | ||
|
|
||
| @Test("Protocol error becomes .error with MindboxError.createJSON payload") | ||
| func protocolError_becomesError() { | ||
| let pe = ProtocolError(status: .protocolError, errorMessage: "Bad", httpStatusCode: 400) | ||
| let outgoing = TransparentView.makeSyncOperationResponse( | ||
| result: .failure(.protocolError(pe)), | ||
| result: .failure(.invalidResponse(httpResponse)), | ||
| action: action, | ||
| id: requestId | ||
| ) | ||
|
|
||
| #expect(outgoing.type == .error) | ||
| if case .string(let value) = outgoing.payload { | ||
| #expect(value.contains("MindboxError")) | ||
| #expect(value.contains("ProtocolError")) | ||
| } else { | ||
| Issue.record("Expected .string payload") | ||
| } | ||
| let payload = try decodedErrorPayload(outgoing) | ||
| #expect(payload["httpStatusCode"] as? String == "403") | ||
| #expect((payload["errorMessage"] as? String)?.isEmpty == false) | ||
| } | ||
|
|
||
| @Test("Unknown error payload is the data contents with errorKey 'unknown'") | ||
| func unknownError_payloadIsDataContentsOnly() throws { | ||
| let underlying = NSError(domain: "test", code: 1, userInfo: [NSLocalizedDescriptionKey: "Something exploded"]) | ||
|
|
||
| let outgoing = TransparentView.makeSyncOperationResponse( | ||
| result: .failure(.unknown(underlying)), | ||
| action: action, | ||
| id: requestId | ||
| ) | ||
|
|
||
| let payload = try decodedErrorPayload(outgoing) | ||
| #expect(payload["errorKey"] as? String == "unknown") | ||
| #expect(payload["errorMessage"] as? String == "Something exploded") | ||
| } | ||
|
|
||
| // MARK: - id and action propagated | ||
|
|
||
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.
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.
Pre-existing on develop, but fair — fixed in 172f622: the fallback is now compact valid JSON with correct key names.