fix: do not log twice OCPP request sending error
authorJérôme Benoit <jerome.benoit@sap.com>
Mon, 20 Nov 2023 14:50:12 +0000 (15:50 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Mon, 20 Nov 2023 14:50:12 +0000 (15:50 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ocpp/OCPPRequestService.ts

index c24742d771c636c9cb7c33271770f3ee96a09e77..77e87f43e31be8550c5e568cbdbc71c5e63c8a54 100644 (file)
@@ -374,13 +374,12 @@ export abstract class OCPPRequestService {
           reject(ocppError);
         };
 
-        const rejectWithOcppError = (ocppError: OCPPError): void => {
-          // Reject response
-          if (messageType !== MessageType.CALL_MESSAGE) {
-            return reject(ocppError);
+        const rejectAndCleanRequestsCache = (ocppError: OCPPError): void => {
+          // Remove request from the cache
+          if (messageType === MessageType.CALL_MESSAGE) {
+            chargingStation.requests.delete(messageId);
           }
-          // Reject and remove request from the cache
-          return errorCallback(ocppError, false);
+          return reject(ocppError);
         };
 
         const handleSendError = (ocppError: OCPPError): void => {
@@ -400,7 +399,7 @@ export abstract class OCPPRequestService {
             // Reject and keep request in the cache
             return reject(ocppError);
           }
-          return rejectWithOcppError(ocppError);
+          return rejectAndCleanRequestsCache(ocppError);
         };
 
         if (chargingStation.stationInfo?.enableStatistics === true) {
@@ -417,7 +416,7 @@ export abstract class OCPPRequestService {
         if (chargingStation.isWebSocketConnectionOpened() === true) {
           const beginId = PerformanceStatistics.beginMeasure(commandName);
           const sendTimeout = setTimeout(() => {
-            return rejectWithOcppError(
+            return rejectAndCleanRequestsCache(
               new OCPPError(
                 ErrorType.GENERIC_ERROR,
                 `Timeout for message id '${messageId}'`,