Undefined safeFields revert to data #71

This commit is contained in:
Zak Barbuto 2018-03-05 14:09:51 +10:30
parent d17d2a9551
commit 0ce15b2d27
2 changed files with 21 additions and 1 deletions

View File

@ -91,6 +91,8 @@ function fillSafeFields(data, err, safeFields) {
}
safeFields.forEach(function(field) {
data[field] = err[field];
if (err[field] !== undefined) {
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) {
var error = new ErrorWithProps({
name: 'Error',