From 7bb8a5bd11c64ac9d9f9efa922fdecf726617bde Mon Sep 17 00:00:00 2001 From: Tim Alby Date: Wed, 3 Jul 2019 14:10:31 +0200 Subject: [PATCH] handle custom errors created without info --- libraries/o-error/index.js | 4 +++- libraries/o-error/test/error-type-class.test.js | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/libraries/o-error/index.js b/libraries/o-error/index.js index 565e8b9e4e..3cde7b6c1f 100644 --- a/libraries/o-error/index.js +++ b/libraries/o-error/index.js @@ -30,7 +30,9 @@ class ErrorTypeError extends Error { constructor ({ message, info }) { super(message) this.name = this.constructor.name - this.info = info + if (info) { + this.info = info + } } /** diff --git a/libraries/o-error/test/error-type-class.test.js b/libraries/o-error/test/error-type-class.test.js index fc1e854e6a..0e97d927ce 100644 --- a/libraries/o-error/test/error-type-class.test.js +++ b/libraries/o-error/test/error-type-class.test.js @@ -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', () => {