From f7be0fbec76c70ae3281f6b0449a7634cd9a091d Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sun, 28 Jan 2024 14:35:30 +0100 Subject: [PATCH] fix: recreate stack trace on BaseError only if needed MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/exception/BaseError.ts | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/exception/BaseError.ts b/src/exception/BaseError.ts index 6b9ea70f..0f41c331 100644 --- a/src/exception/BaseError.ts +++ b/src/exception/BaseError.ts @@ -3,12 +3,8 @@ export class BaseError extends Error { super(message) this.name = new.target.name Object.setPrototypeOf(this, new.target.prototype) - typeof Error.captureStackTrace === 'function' - ? Error.captureStackTrace(this, this.constructor) - : this.createStack() - } - - private createStack (): void { - this.stack = new Error().stack + if (this.stack == null && typeof BaseError.captureStackTrace === 'function') { + BaseError.captureStackTrace(this, this.constructor) + } } } -- 2.34.1