I'm having a strange problem with Parse-Server.
I get sometimes the following error:
ParseError { code: 101, message: 'Object not found.' }
It usually happen after an error in cloud code, in whatever function that use the object even if there is no update in it (like the following function that just doing a find but still create the bug if it fail for any reason like a bad code line). However I'm not sure this is the cause.
I have that simple function in Cloud Code:
const user = req.user
const card_id = cid(req, user)
const base_error = global.i18n.__('errors.default')
if(!card_id) return res.error(base_error)
console.log('CID: ' + card_id + ' | UID: ' + user.id)
new Parse.Query(global.m.Card).get(card_id)
.then((card) => {
if((new Date) - card.updatedAt > OSC.syncDelay)
return _CARD.sync(card.get('onum'))
return card
})
.then((card) => {
res.success(card)
})
.then(null, (error) => {
if(Array.isArray(error)) error = error[0]
console.log(error) // HERE is where the error is logged
res.error(base_error)
})
Here is what the console.log print:
CID: PqOMwi5y60 | UID: QldBflokJV
Here is how the Card ACLs are defined (with an update, not at creation):
const cardACL = card.getACL()
cardACL.setReadAccess(user, true)
cardACL.setWriteAccess(user, true)
if(memory.admin) {
cardACL.setReadAccess(memory.admin, true)
cardACL.setWriteAccess(memory.admin, true)
}
card.setACL(cardACL)
Finally, this is what I have in my Database for the card object Permissions/ACLs:
"_id" : "PqOMwi5y60",
"_wperm" : [
"role:Administrator",
"QldBflokJV"
],
"_rperm" : [
"role:Administrator",
"QldBflokJV"
],
"_acl" : {
"role:Administrator" : {
"w" : true,
"r" : true
}
}
Am I doing something wrong ?
Because your ACL contains the user (since only the user or admin can read and write from/to the object) in your query you need also to send the session token of the logged in user. So at the end your code should look like the following:
const user = req.user
const card_id = cid(req, user)
const base_error = global.i18n.__('errors.default')
if(!card_id) return res.error(base_error)
console.log('CID: ' + card_id + ' | UID: ' + user.id)
new Parse.Query(global.m.Card).get(card_id,{
sessionToken: request.user.get("sessionToken")
})
.then((card) => {
if((new Date) - card.updatedAt > OSC.syncDelay)
return _CARD.sync(card.get('onum'))
return card
})
.then((card) => {
res.success(card)
})
.then(null, (error) => {
if(Array.isArray(error)) error = error[0]
console.log(error) // HERE is where the error is logged
res.error(base_error)
})
Please notice that i sent also the session token in the query.