I've written the following code (Coffeescript):
Promise.try ->
req.model("AuditLogEntry").getAll([], start: start, limit: limit, require: yes)
.catch req.db.EmptyResponse, (err) ->
throw util.NotFound()
.then (entries) ->
res.send entries.json()
... and I made the mistake of trying to filter by req.db.EmptyResponse (which was undefined) rather than by the correct attribute req.db.EmptyError. However, bluebird didn't remark on me passing undefined as filter - instead, it gave me the following error:
TypeError: Cannot call method 'then' of undefined
at module.exports (/home/sven/projects/anonnews3/routes/audit-log.js:27:6)
at handleReturn (/home/sven/projects/anonnews3/node_modules/express-promise-router/lib/express-promise-router.js:27:27)
at Object.handle (/home/sven/projects/anonnews3/node_modules/express-promise-router/lib/express-promise-router.js:55:9)
at next_layer (/home/sven/projects/anonnews3/node_modules/express/lib/router/route.js:103:13)
[...]
This refers to the .then call in line 5 of the code snippet above. Instead of throwing a fairly cryptic error (why does .catch return undefined?), it should probably throw an error of some sort that the specified filter is invalid - after all, it's not an Error type nor a function.
I've written the following code (Coffeescript):
... and I made the mistake of trying to filter by
req.db.EmptyResponse(which wasundefined) rather than by the correct attributereq.db.EmptyError. However, bluebird didn't remark on me passingundefinedas filter - instead, it gave me the following error:This refers to the
.thencall in line 5 of the code snippet above. Instead of throwing a fairly cryptic error (why does.catchreturnundefined?), it should probably throw an error of some sort that the specified filter is invalid - after all, it's not anErrortype nor a function.