You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be great if this library returned Error objects with useful types and functionality (e.g. ValidationError, DatabaseError) instead of just objects and/or arrays as present.
Here's a great example of how the present implementation creates a pain point:
varresourceful=require('resourceful');// Caution: Script creates db named 'test_dummy'resourceful.use('couchdb',{database: 'test_dummy'});vardb=resourceful.connection.connection;varAuthor=resourceful.define('author');Author.string('name',{required: true});db.create(function(err,result){Author.create({id: 'Marak',name: 'Marak',},function(err,marak){marak.name=undefined;// Save resource fails because of validation errormarak.save(function(err,result){console.log(err);// [ { attribute: 'required', property: 'name', expected: true, actual: undefined, message: 'is required' } ]marak.name='Marak';db.destroy(function(err,result){// Save resource fails because db does not existmarak.save(function(err,result){console.log(err);// { error: 'not_found', reason: 'no_db_file', status: 404 }db.destroy(function(err,result){});});});})});});
Note that the save() method on the resource returns an array of objects on a validation error and a different object on a database error. Now imagine you're coding up an API controller that has to determine whether to return a 400 in the case of a validation error and a 500 for a database failure. The logic to make that determination would be quite awkward and ugly.
I also have a Python background so I'm used to making liberal use of exceptions. You guys might have your reasons for the way things are now, so this is just a feature suggestion.
The text was updated successfully, but these errors were encountered:
It would be great if this library returned Error objects with useful types and functionality (e.g. ValidationError, DatabaseError) instead of just objects and/or arrays as present.
Here's a great example of how the present implementation creates a pain point:
Note that the save() method on the resource returns an array of objects on a validation error and a different object on a database error. Now imagine you're coding up an API controller that has to determine whether to return a 400 in the case of a validation error and a 500 for a database failure. The logic to make that determination would be quite awkward and ugly.
I'll observe that Mongoose returns custom error objects in situations like this (https://github.com/LearnBoost/mongoose/tree/master/lib/errors) and I've certainly read plenty of arguments in support of this approach (http://dustinsenos.com/articles/customErrorsInNode).
I also have a Python background so I'm used to making liberal use of exceptions. You guys might have your reasons for the way things are now, so this is just a feature suggestion.
The text was updated successfully, but these errors were encountered: