diff --git a/lib/dao.js b/lib/dao.js index 6d3175da..224e6cdf 100644 --- a/lib/dao.js +++ b/lib/dao.js @@ -331,9 +331,20 @@ setRemoting(DataAccessObject.findById, { description: 'Find a model instance by id from the data source', accepts: {arg: 'id', type: 'any', description: 'Model id', required: true}, returns: {arg: 'data', type: 'any', root: true}, - http: {verb: 'get', path: '/:id'} + http: {verb: 'get', path: '/:id'}, + rest: {after: convertNullToNotFoundError} }); +function convertNullToNotFoundError(ctx, cb) { + if (ctx.result !== null) return cb(); + + var modelName = ctx.method.sharedClass.name; + var id = ctx.getArgByName('id'); + var msg = 'Unkown "' + modelName + '" id "' + id + '".'; + var error = new Error(msg); + error.statusCode = error.status = 404; + cb(error); +} // alias function for backwards compat. DataAccessObject.all = function () {