From: Jérôme Benoit Date: Sun, 28 Jan 2024 13:35:30 +0000 (+0100) Subject: fix: recreate stack trace on BaseError only if needed X-Git-Tag: v1.2.33~16 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=f7be0fbec76c70ae3281f6b0449a7634cd9a091d;p=e-mobility-charging-stations-simulator.git fix: recreate stack trace on BaseError only if needed Signed-off-by: Jérôme Benoit --- 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) + } } }