Hide offending properties from the error object

This commit is contained in:
Raymond Feng 2018-10-18 14:46:13 -07:00
parent bae60d1c08
commit 71f2e54de5
2 changed files with 6 additions and 4 deletions

View File

@ -32,6 +32,7 @@ var g = require('strong-globalize')();
var traverse = require('traverse');
var assert = require('assert');
var Promise = require('bluebird');
var debug = require('debug')('loopback:juggler:utils');
function safeRequire(module) {
try {
@ -362,11 +363,13 @@ function validateKeys(where, prohibitedKeys) {
return x;
});
if (offendingKeys.length) {
const msg = 'Properties "' + offendingKeys.join(', ') + '" are not allowed in query';
const msg = 'Invalid properties are used in query';
const err = new Error(msg);
err.code = 'PROPERTY_NOT_ALLOWED_IN_QUERY';
err.statusCode = 400;
err.details = {properties: offendingKeys, where: where};
err.details = {where: where};
debug('Hidden or protected properties %j are used in query: %j',
offendingKeys, where, err);
throw err;
}
return result;

View File

@ -332,10 +332,9 @@ describe('ModelDefinition class', function() {
function assertPropertyNotAllowed(err) {
should.exist(err);
err.message.should.match(/Properties "secret" are not allowed in query/);
err.message.should.match(/Invalid properties are used in query/);
err.code.should.equal('PROPERTY_NOT_ALLOWED_IN_QUERY');
err.statusCode.should.equal(400);
err.details.should.have.property('properties');
err.details.should.have.property('where');
}