Skip to content

"Cannot call method 'then' of undefined" when specifying an invalid .catch filter #318

Description

@joepie91

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions