Skip to content

Commit

Permalink
Improved error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
kosmikko committed Apr 25, 2014
1 parent eaea8a6 commit 2acf2bd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
8 changes: 7 additions & 1 deletion lib/collections/acl_collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var _debug = require('debug');
var logId = 'serverbone:collections:acl';
var acl = require('../acl');
var errors = require('../errors');
var util = require('util');
var debug = {
trace: _debug(logId + ':trace'),
log: _debug(logId + ':log'),
Expand Down Expand Up @@ -81,7 +82,12 @@ var ACLCollection = BaseCollection.extend({
var canAccess = this.canAccess(options.action, options.actor);
if (!canAccess) {
debug.log('no access:' + options.action + ', ' + this.type + ', ' + this.indexKey);
var error = new errors.ForbiddenError('No access to ' + options.action);
var errorMsg = util.format(
'No access to %s (%s)',
options.action,
this.name || this.indexKey
);
var error = new errors.ForbiddenError(errorMsg);
return error;
}
}
Expand Down
9 changes: 8 additions & 1 deletion lib/collections/acl_index_mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ var _ = require('lodash');
var ACLCollection = require('./acl_collection');
var IndexMixin = require('./index_mixin');
var _debug = require('debug');
var util = require('util');
var logId = 'serverbone:collections:acl_index_mixin';
var acl = require('../acl');
var errors = require('../errors');
Expand Down Expand Up @@ -60,7 +61,13 @@ var ACLIndexMixin = _.extend({}, IndexMixin, {
var canAccess = this.canAccess(options.action, options.actor, model);
if (!canAccess) {
debug.log('no access:' + options.action + ', ' + this.type + ', ' + this.indexKey);
var error = new errors.ForbiddenError('No access to ' + options.action);
var errorMsg = util.format(
'No access to %s (%s)',
options.action,
this.name || this.indexKey
);
var error = new errors.ForbiddenError(errorMsg);

return error;
}
}
Expand Down
3 changes: 1 addition & 2 deletions lib/models/acl_model.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ var ACLModel = BaseModel.extend({
if (canAccess && changedAttrs) {
var schemaProps = Object.keys(this.schema.properties);
changedProps = Object.keys(changedAttrs);

changedProps = _.filter(changedProps, function(prop) {
return schemaProps.indexOf(prop) > -1 && this.get(prop) !== attrs[prop];
}, this);
Expand All @@ -197,7 +196,7 @@ var ACLModel = BaseModel.extend({
if ((!canAccess && changedAttrs) || (noAccessTo && noAccessTo.length > 0) ) {
debug.log('Failing validation, no access with action %s to %s', action, JSON.stringify(noAccessTo));
var errorMsg = util.format('No access to %s %s (%s)', action, this.type, this.id);
if (noAccessTo) errorMsg+= ' fields:' + noAccessTo;
if (noAccessTo) errorMsg += ' fields:' + noAccessTo;
var error = new errors.ForbiddenError(errorMsg);
if (options && options.error) {
if (options.error.length === 3) {
Expand Down

0 comments on commit 2acf2bd

Please sign in to comment.