From 2ebd83d0686b06cfade9322a2d94210774c6ea34 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sun, 28 Jan 2024 15:34:06 +0100 Subject: [PATCH] refactor: use Error static function to generate BaseError stack trace 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 | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/exception/BaseError.ts b/src/exception/BaseError.ts index 0f41c331..ce37fd98 100644 --- a/src/exception/BaseError.ts +++ b/src/exception/BaseError.ts @@ -1,10 +1,13 @@ export class BaseError extends Error { + public date: Date + public constructor (message?: string) { super(message) this.name = new.target.name + this.date = new Date() Object.setPrototypeOf(this, new.target.prototype) - if (this.stack == null && typeof BaseError.captureStackTrace === 'function') { - BaseError.captureStackTrace(this, this.constructor) + if (typeof Error.captureStackTrace === 'function') { + Error.captureStackTrace(this, BaseError) } } } -- 2.34.1