Throw 404 when a model is not found during remote construction

This commit is contained in:
Ritchie Martori 2013-06-19 17:03:15 -07:00
parent cc51b07596
commit b426caccd3
1 changed files with 12 additions and 1 deletions

View File

@ -179,7 +179,18 @@ asteroid.createModel = function (name, properties, options) {
} else if(data) { } else if(data) {
fn(null, new ModelCtor(data)); fn(null, new ModelCtor(data));
} else if(id) { } else if(id) {
ModelCtor.find(id, fn); ModelCtor.find(id, function (err, model) {
if(err) {
fn(err);
} else if(model) {
fn(null, model);
} else {
err = new Error('could not find a model with id ' + id);
err.statusCode = 404;
fn(err);
}
});
} else { } else {
fn(new Error('must specify an id or data')); fn(new Error('must specify an id or data'));
} }