Throw 404 when a model is not found during remote construction
This commit is contained in:
parent
cc51b07596
commit
b426caccd3
|
@ -179,7 +179,18 @@ asteroid.createModel = function (name, properties, options) {
|
|||
} else if(data) {
|
||||
fn(null, new ModelCtor(data));
|
||||
} 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 {
|
||||
fn(new Error('must specify an id or data'));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue