handle custom errors created without info

This commit is contained in:
Tim Alby 2019-07-03 14:10:31 +02:00
parent 5bf235c549
commit 7bb8a5bd11
2 changed files with 14 additions and 1 deletions

View file

@ -30,8 +30,10 @@ class ErrorTypeError extends Error {
constructor ({ message, info }) {
super(message)
this.name = this.constructor.name
if (info) {
this.info = info
}
}
/**
* Wrap the given error, which caused this error.

View file

@ -95,6 +95,17 @@ describe('errorType.Error', () => {
)
}
})
it('handles a custom error without info', () => {
try {
throw new CustomError1({})
expect.fail('should have thrown')
} catch (e) {
expect(errorType.getFullInfo(e)).to.deep.equal({})
let infoKey = Object.keys(e).find(k => k === 'info')
expect(infoKey).to.not.exist
}
})
})
describe('errorType.ErrorWithStatusCode', () => {