Unitech / angular-bridge

Link models easily via a REST interface between Mongoose/Node-Express/Angular.js
208 stars 22 forks source link

ReferenceError: error is not defined #4

Closed vegar closed 11 years ago

vegar commented 11 years ago

Angular-bridge looks really interesting.

There seems to be something wrong in the error handling for posting a new document:

AngularBridge.prototype.collectionPost = function() { 
return _.bind(function(req, res, next) {
    if (!req.resource) { next(); return; }
    var self = this;
    if (!req.body) throw new Error('Nothing submitted.');

    var epured_body = this.epureRequest(req, req.resource);
    var doc = new req.resource.model(epured_body);

    doc.save(function(err) {
        if (err) { error(err); return; }                                     // <-- error not defined
        if(doc.schema.methods.post) doc.schema.methods.post();
        res.send(doc);
    });
}, this); 
};

The error handling seems to be a little inconsistent through out the library. Some places an exception is thrown, others uses the response object to send an error object. Some places the actual error is returned, in other places only success = false is sent.

And as far as I can see, all errors are returned with an 200 OK status. Is that right?

Unitech commented 11 years ago

Thanks fo this pull request, I will also add more tests