Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Return proper error objects instead regular objects / arrays / strings. #123

jsdalton opened this Issue · 5 comments

4 participants


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:

var resourceful = require('resourceful');

// Caution: Script creates db named 'test_dummy'
resourceful.use('couchdb', { database: 'test_dummy' });

var db = resourceful.connection.connection;

var Author = resourceful.define('author');
Author.string('name', { required: true });

db.create(function (err, result) {
    id: 'Marak',
    name: 'Marak',
  }, function(err, marak){ = undefined;

    // Save resource fails because of validation error, result){
      console.log(err); // [ { attribute: 'required', property: 'name', expected: true, actual: undefined, message: 'is required' } ] = 'Marak';
      db.destroy(function (err, result) {

        // Save resource fails because db does not exist, 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'll observe that Mongoose returns custom error objects in situations like this ( and I've certainly read plenty of arguments in support of this approach (

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.


Express will not handle correctly with these plain objects. Won't send them to global error handlers. Wried!


I think this can be fixed almost entirely in cradle flatiron/cradle#216


There are more than one database solution than cradle...... not to mention a large group of people are using other DBs like mongo and mysql.


resourceful may be the most "resourceful" module in flatiron series. Hope it will get better and more active.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.