Fix all misused promises
authorJérôme Benoit <jerome.benoit@sap.com>
Sat, 14 Jan 2023 19:00:41 +0000 (20:00 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Sat, 14 Jan 2023 19:00:41 +0000 (20:00 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ChargingStation.ts
src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts

index 26969c4f5fecb1d6ee5d9d2b6c838f900eaa4453..ad9789dc6ae187a94a108b202530c53f1539c80a 100644 (file)
@@ -377,12 +377,15 @@ export default class ChargingStation {
       this.getHeartbeatInterval() > 0 &&
       !this.heartbeatSetInterval
     ) {
-      // eslint-disable-next-line @typescript-eslint/no-misused-promises
-      this.heartbeatSetInterval = setInterval(async (): Promise<void> => {
-        await this.ocppRequestService.requestHandler<HeartbeatRequest, HeartbeatResponse>(
-          this,
-          RequestCommand.HEARTBEAT
-        );
+      this.heartbeatSetInterval = setInterval(() => {
+        this.ocppRequestService
+          .requestHandler<HeartbeatRequest, HeartbeatResponse>(this, RequestCommand.HEARTBEAT)
+          .catch((error) => {
+            logger.error(
+              `${this.logPrefix()} Error while sending '${RequestCommand.HEARTBEAT}':`,
+              error
+            );
+          });
       }, this.getHeartbeatInterval());
       logger.info(
         this.logPrefix() +
@@ -448,18 +451,16 @@ export default class ChargingStation {
       return;
     }
     if (interval > 0) {
-      // eslint-disable-next-line @typescript-eslint/no-misused-promises
-      this.getConnectorStatus(connectorId).transactionSetInterval = setInterval(
-        // eslint-disable-next-line @typescript-eslint/no-misused-promises
-        async (): Promise<void> => {
-          // FIXME: Implement OCPP version agnostic helpers
-          const meterValue: MeterValue = OCPP16ServiceUtils.buildMeterValue(
-            this,
-            connectorId,
-            this.getConnectorStatus(connectorId).transactionId,
-            interval
-          );
-          await this.ocppRequestService.requestHandler<MeterValuesRequest, MeterValuesResponse>(
+      this.getConnectorStatus(connectorId).transactionSetInterval = setInterval(() => {
+        // FIXME: Implement OCPP version agnostic helpers
+        const meterValue: MeterValue = OCPP16ServiceUtils.buildMeterValue(
+          this,
+          connectorId,
+          this.getConnectorStatus(connectorId).transactionId,
+          interval
+        );
+        this.ocppRequestService
+          .requestHandler<MeterValuesRequest, MeterValuesResponse>(
             this,
             RequestCommand.METER_VALUES,
             {
@@ -467,10 +468,14 @@ export default class ChargingStation {
               transactionId: this.getConnectorStatus(connectorId).transactionId,
               meterValue: [meterValue],
             }
-          );
-        },
-        interval
-      );
+          )
+          .catch((error) => {
+            logger.error(
+              `${this.logPrefix()} Error while sending '${RequestCommand.METER_VALUES}':`,
+              error
+            );
+          });
+      }, interval);
     } else {
       logger.error(
         `${this.logPrefix()} Charging station ${
index 68d9da4daf3c2b3bb98a7effef67fb638b2d775b..fbae8f85b05382e328bb0a931834fc35be936026 100644 (file)
@@ -1081,19 +1081,27 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
         });
         let uploadResponse: FTPResponse;
         if (accessResponse.code === 220) {
-          // eslint-disable-next-line @typescript-eslint/no-misused-promises
-          ftpClient.trackProgress(async (info) => {
+          ftpClient.trackProgress((info) => {
             logger.info(
               `${chargingStation.logPrefix()} ${
                 info.bytes / 1024
               } bytes transferred from diagnostics archive ${info.name}`
             );
-            await chargingStation.ocppRequestService.requestHandler<
-              OCPP16DiagnosticsStatusNotificationRequest,
-              OCPP16DiagnosticsStatusNotificationResponse
-            >(chargingStation, OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION, {
-              status: OCPP16DiagnosticsStatus.Uploading,
-            });
+            chargingStation.ocppRequestService
+              .requestHandler<
+                OCPP16DiagnosticsStatusNotificationRequest,
+                OCPP16DiagnosticsStatusNotificationResponse
+              >(chargingStation, OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION, {
+                status: OCPP16DiagnosticsStatus.Uploading,
+              })
+              .catch((error) => {
+                logger.error(
+                  `${chargingStation.logPrefix()} ${moduleName}.handleRequestGetDiagnostics: Error while sending '${
+                    OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION
+                  }'`,
+                  error
+                );
+              });
           });
           uploadResponse = await ftpClient.uploadFrom(
             path.join(