Hide offending properties from the error object
This commit is contained in:
parent
bae60d1c08
commit
71f2e54de5
|
@ -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;
|
||||
|
|
|
@ -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');
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue