TypeError when trying to update entity in data store
k
karimsa
started a topic
over 6 years ago
Hi, guys.
I've ran into a problem where (occasionally, not always) my endpoint throws a BLRuntimeError with the debug message `TypeError: Cannot call method 'call' of undefined`. I tried inserting some log statements to lower down the problem to a single line, and it seems to be when I do a .update() on a collection. My code looks similar to this:
```
var onRequest = function (req, res, mods) {
var ds = mods.collectionAccess.collection('dsdb');
ds.findOne({ _id: req.body._id }, function (err, dsrow) {
if (!err && !!dsrow) {
dsrow.prop = req.body.val;
ds.update(dsrow, function () {
res.body = 'Updated data successfully';
res.complete(200);
});
}
});
};
```
I find it strange that the error only occurs sometimes, and it is not caught by a try/catch statement around my entire endpoint.
The callback requires three arguments; error, response, and body. See also http://devcenter.kinvey.com/rest/reference/business-logic/reference.html#collection-access-module
That could be the issue.
k
karimsa
said
over 6 years ago
Yes, and req is request and mods is modules.
C
Caroline
said
over 6 years ago
Okay, so I am assuming that you're using shorthand for some of your code? Like res.complete is actually response.complete in your code?
k
karimsa
said
over 6 years ago
This is similar. I can't disclose the actual code due to some confidentiality issues.
C
Caroline
said
over 6 years ago
Karisma, I am trying to clarify if this is the code you are using, or like you said this is "similar" to the code you are using.
karimsa
I've ran into a problem where (occasionally, not always) my endpoint throws a BLRuntimeError with the debug message `TypeError: Cannot call method 'call' of undefined`. I tried inserting some log statements to lower down the problem to a single line, and it seems to be when I do a .update() on a collection. My code looks similar to this:
```
var onRequest = function (req, res, mods) {
var ds = mods.collectionAccess.collection('dsdb');
ds.findOne({ _id: req.body._id }, function (err, dsrow) {
if (!err && !!dsrow) {
dsrow.prop = req.body.val;
ds.update(dsrow, function () {
res.body = 'Updated data successfully';
res.complete(200);
});
}
});
};
```
I find it strange that the error only occurs sometimes, and it is not caught by a try/catch statement around my entire endpoint.
All comments are appreciated! Thanks.