Added consistent error handling throughout the models

This commit is contained in:
Hannah Wolfe 2013-06-16 22:36:28 +01:00
parent 0a500bd104
commit 0d5b6e8915
4 changed files with 16 additions and 12 deletions

View File

@ -4,6 +4,7 @@
"use strict";
var GhostBookshelf = require('./base'),
errors = require('../errorHandling'),
knex = GhostBookshelf.Knex;
module.exports = {
@ -18,10 +19,10 @@
var migration = require('../data/migration/001');
return migration.down().then(function () {
return migration.up();
});
}).then(function () {
}, errors.logAndThrowError);
}, errors.logAndThrowError).then(function () {
console.log('models loaded');
});
}, errors.logAndThrowError);
}
};

View File

@ -7,6 +7,7 @@
_ = require('underscore'),
uuid = require('node-uuid'),
when = require('when'),
errors = require('../errorHandling'),
Showdown = require('showdown'),
converter = new Showdown.converter(),
User = require('./user').User,
@ -143,8 +144,8 @@
pages: Math.ceil(totalPosts / opts.limit),
total: totalPosts
};
});
});
}, errors.logAndThrowError);
}, errors.logAndThrowError);
},
permissable: function (postModelOrId, userId, action_type, userPermissions) {
@ -157,7 +158,7 @@
if (_.isNumber(postModelOrId) || _.isString(postModelOrId)) {
return this.read({id: postModelOrId}).then(function (foundPostModel) {
return self.permissable(foundPostModel, userId, action_type, userPermissions);
});
}, errors.logAndThrowError);
}
// TODO: This logic is temporary, will probably need to be updated

View File

@ -5,6 +5,7 @@
GhostBookshelf = require('./base'),
uuid = require('node-uuid'),
_ = require('underscore'),
errors = require('../errorHandling'),
when = require('when');
// Each setting is saved as a separate row in the database,
@ -36,7 +37,7 @@
if (item.toJSON) { item = item.toJSON(); }
return settings.forge({ key: item.key }).fetch().then(function (setting) {
return setting.set('value', item.value).save();
});
}, errors.logAndThrowError);
});
}
});

View File

@ -8,6 +8,7 @@
_ = require('underscore'),
uuid = require('node-uuid'),
when = require('when'),
errors = require('../errorHandling'),
nodefn = require('when/node/function'),
bcrypt = require('bcrypt-nodejs'),
Posts = require('./post').Posts,
@ -85,8 +86,8 @@
userData.password = hash;
GhostBookshelf.Model.add.call(UserRole, userRoles);
return GhostBookshelf.Model.add.call(User, userData);
});
});
}, errors.logAndThrowError);
}, errors.logAndThrowError);
/**
* Temporarily replacing the function below with another one that checks
@ -122,8 +123,8 @@
return when.reject(new Error('Passwords do not match'));
}
return user;
});
});
}, errors.logAndThrowError);
}, errors.logAndThrowError);
},
effectivePermissions: function (id) {
@ -152,7 +153,7 @@
});
return when.resolve(allPerms);
});
}, errors.logAndThrowError);
}
});