throw config error based on the joi validation error (#29137) (#29181)

This commit is contained in:
Brandon Kobel 2019-01-23 15:18:36 -08:00 committed by GitHub
parent 3ae2b81acc
commit bcddc14012
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 3 deletions

View file

@ -124,7 +124,10 @@ export class Config {
});
if (results.error) {
throw results.error;
const error = new Error(results.error.message);
error.name = results.error.name;
error.stack = results.error.stack;
throw error;
}
this[vals] = results.value;

View file

@ -174,7 +174,7 @@ describe('lib/config/config', function () {
});
it('should thow an exception when setting a value with the wrong type', function (done) {
expect.assertions(2);
expect.assertions(4);
const run = function () {
config.set('test.enable', 'something');
@ -184,7 +184,11 @@ describe('lib/config/config', function () {
run();
} catch (err) {
expect(err).toHaveProperty('name', 'ValidationError');
expect(err.details[0].message).toBe('"enable" must be a boolean');
expect(err).toHaveProperty('message',
'child \"test\" fails because [child \"enable\" fails because [\"enable\" must be a boolean]]'
);
expect(err).not.toHaveProperty('details');
expect(err).not.toHaveProperty('_object');
}
done();