Merge pull request #72 from strongloop/fix/71-safe-fields-defaults

Undefined safeFields revert to data #71
This commit is contained in:
Miroslav Bajtoš 2018-03-05 09:58:12 +01:00 committed by GitHub
commit 93792910c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 1 deletions

View File

@ -91,6 +91,8 @@ function fillSafeFields(data, err, safeFields) {
} }
safeFields.forEach(function(field) { safeFields.forEach(function(field) {
if (err[field] !== undefined) {
data[field] = err[field]; data[field] = err[field];
}
}); });
} }

View File

@ -300,6 +300,24 @@ describe('strong-error-handler', function() {
}); });
}); });
it('safe fields falls back to existing data', function(done) {
var error = new ErrorWithProps({
name: 'Error',
isSafe: false,
});
givenErrorHandlerForError(error, {
safeFields: ['statusCode', 'isSafe'],
});
requestJson().end(function(err, res) {
if (err) return done(err);
expect(res.body.error.statusCode).to.equal(500);
expect(res.body.error.isSafe).to.equal(false);
done();
});
});
it('should allow setting safe fields when status=4xx', function(done) { it('should allow setting safe fields when status=4xx', function(done) {
var error = new ErrorWithProps({ var error = new ErrorWithProps({
name: 'Error', name: 'Error',