Add error handling in one performance storage class
[e-mobility-charging-stations-simulator.git] / src / performance / storage / JSONFileStorage.ts
index cc7920a0a4aadfe40ffb6710dddf0e012f1ea9ed..25ba236703f4b60393b963fa0f349b7c01ea9b9d 100644 (file)
@@ -33,7 +33,9 @@ export class JSONFileStorage extends Storage {
 
   public open(): void {
     try {
-      this.fd = fs.openSync(this.dbName, 'a+');
+      if (!this?.fd) {
+        this.fd = fs.openSync(this.dbName, 'a+');
+      }
     } catch (error) {
       FileUtils.handleFileException(this.logPrefix, Constants.PERFORMANCE_RECORDS_FILETYPE, this.dbName, error);
     }
@@ -41,7 +43,7 @@ export class JSONFileStorage extends Storage {
 
   public close(): void {
     try {
-      if (this.fd) {
+      if (this?.fd) {
         fs.closeSync(this.fd);
         this.fd = null;
       }