Skip to content

Commit 513721c

Browse files
Copilotcubap
andcommitted
Add null check for rootObj after database query
Co-authored-by: cubap <1119165+cubap@users.noreply.github.com>
1 parent f64e5d6 commit 513721c

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

controllers/delete.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,9 @@ async function getAllVersions(obj) {
228228
//Use _id for indexed query performance instead of @id
229229
const primeHexId = parseDocumentID(primeID)
230230
rootObj = await db.findOne({"$or":[{"_id": primeHexId}, {"__rerum.slug": primeHexId}]})
231+
if (!rootObj) {
232+
throw new Error(`Root object with id '${primeID}' not found in database`)
233+
}
231234
} else {
232235
//primeID is undefined or null, cannot proceed
233236
throw new Error("Object has no valid history.prime value")

controllers/utils.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,9 @@ async function getAllVersions(obj) {
207207
//Use _id for indexed query performance instead of @id
208208
const primeHexId = parseDocumentID(primeID)
209209
rootObj = await db.findOne({"$or":[{"_id": primeHexId}, {"__rerum.slug": primeHexId}]})
210+
if (!rootObj) {
211+
throw new Error(`Root object with id '${primeID}' not found in database`)
212+
}
210213
} else {
211214
//primeID is undefined or null, cannot proceed
212215
throw new Error("Object has no valid history.prime value")

0 commit comments

Comments
 (0)