fix: recreate stack trace on BaseError only if needed
authorJérôme Benoit <jerome.benoit@sap.com>
Sun, 28 Jan 2024 13:35:30 +0000 (14:35 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Sun, 28 Jan 2024 13:35:30 +0000 (14:35 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/exception/BaseError.ts

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