File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed
Networking/Networking/Model/Product Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -71,7 +71,21 @@ internal struct ProductAddOnEnvelope: Decodable {
7171 /// Converts an addOnJsonObject(`Dictionary`) to a `ProductAddOn` entity.
7272 ///
7373 private func decode( addOnJsonObject: AnyDictionary , using decoder: JSONDecoder ) throws -> ProductAddOn {
74+ // It appears to be unexpected crashes when parsing some JSON objects that are not handled inside subsequent `try JSONSerialization.data` call.
75+ // https://github.com/woocommerce/woocommerce-ios/issues/4205
76+ guard JSONSerialization . isValidJSONObject ( addOnJsonObject) else {
77+ throw ProductAddOnEnvelopeError . invalidJsonObject ( addOnJsonObject)
78+ }
79+
7480 let jsonData = try JSONSerialization . data ( withJSONObject: addOnJsonObject, options: . fragmentsAllowed)
7581 return try decoder. decode ( ProductAddOn . self, from: jsonData)
7682 }
7783}
84+
85+ /// Custom errors that can happen during the `ProductAddOnEnvelope` decoding.
86+ ///
87+ public enum ProductAddOnEnvelopeError : Error {
88+ /// Represents an error when a `add-on JSON object` can't be converted to `JSON data`.
89+ ///
90+ case invalidJsonObject( [ String : Any ] )
91+ }
You can’t perform that action at this time.
0 commit comments