Merge pull request #72 from strongloop/fix/71-safe-fields-defaults
Undefined safeFields revert to data #71
This commit is contained in:
commit
93792910c9
|
@ -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];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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',
|
||||
|
|
Loading…
Reference in New Issue