Skip to content

Commit a6324c6

Browse files
committed
fix: reject when cannot create JSON from document
1 parent ee57a6f commit a6324c6

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

ios/CblReactnative.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -523,8 +523,12 @@ class CblReactnative: RCTEventEmitter {
523523
}
524524
var data:[String: Any] = [:]
525525
let documentJson = doc.toJSON()
526-
if let jsonData = documentJson.data(using: .utf8),
527-
let jsonDict = try? JSONSerialization.jsonObject(with: jsonData, options: []) as? [String: Any] {
526+
if !documentJson.isEmpty {
527+
guard let jsonData = documentJson.data(using: .utf8),
528+
let jsonDict = try JSONSerialization.jsonObject(with: jsonData, options: []) as? [String: Any] else {
529+
reject("DOCUMENT_ERROR", "Failed to parse document JSON", nil)
530+
return
531+
}
528532
data["_data"] = jsonDict
529533
} else {
530534
data["_data"] = [:]

src/cblite-js

0 commit comments

Comments
 (0)