Mentions légales du service

Skip to content
Snippets Groups Projects
Commit a2b9e5d7 authored by Ludovic Le Frioux's avatar Ludovic Le Frioux
Browse files

Check CRDT form at first update, catch deserialization exception

parent 4b95a7f4
No related branches found
No related tags found
2 merge requests!48Release v1.1.4,!34Resolve "updateObject should handle CRDT conflict"
Pipeline #198080 passed
......@@ -230,33 +230,32 @@ function updateObject(dbName: string, docName: string, document: string) {
.use(dbName)
.get(docName)
.then((body) => {
const CRDT = crdtlib.crdt.DeltaCRDT.Companion.fromJson(document);
const bodyCRDT = crdtlib.crdt.DeltaCRDT.Companion.fromJson(
JSON.stringify(body)
);
bodyCRDT.merge(CRDT);
const newDocument = JSON.parse(bodyCRDT.toJson());
newDocument._rev = body._rev;
client.db
.use(dbName)
.insert(newDocument, docName)
.catch((error) => {
console.error(
`[SERVER][ERROR] Failed updating document '${docName}' in database '${dbName}'`
);
console.error(error);
});
try {
const CRDT = crdtlib.crdt.DeltaCRDT.Companion.fromJson(document);
const bodyCRDT = crdtlib.crdt.DeltaCRDT.Companion.fromJson(
JSON.stringify(body)
);
bodyCRDT.merge(CRDT);
const newDocument = JSON.parse(bodyCRDT.toJson());
newDocument._rev = body._rev;
client.db.use(dbName).insert(newDocument, docName);
} catch (error) {
console.error(
`[SERVER][ERROR] Failed updating document '${docName}' in database '${dbName}'`
);
console.error(error);
}
})
.catch((error) => {
client.db
.use(dbName)
.insert(JSON.parse(document), docName)
.catch((error) => {
console.error(
`[SERVER][ERROR] Failed updating document '${docName}' in database '${dbName}'`
);
console.error(error);
});
try {
const CRDT = crdtlib.crdt.DeltaCRDT.Companion.fromJson(document);
client.db.use(dbName).insert(JSON.parse(document), docName);
} catch (error) {
console.error(
`[SERVER][ERROR] Failed updating document '${docName}' in database '${dbName}'`
);
console.error(error);
}
});
})
.catch((error) => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment