refactor: use Error static function to generate BaseError stack trace
authorJérôme Benoit <jerome.benoit@sap.com>
Sun, 28 Jan 2024 14:34:06 +0000 (15:34 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Sun, 28 Jan 2024 14:34:06 +0000 (15:34 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/exception/BaseError.ts

index 0f41c331b73aabdcbf12bb6da19ef8a51c6c6cfb..ce37fd98d96df2e88f82eb191e85112db0ad6a4f 100644 (file)
@@ -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)
     }
   }
 }