Do not log response statistics at sending issues
[e-mobility-charging-stations-simulator.git] / src / charging-station / ocpp / OCPPRequestService.ts
index 1bc8e70cd275cab6decf2049d12e6bfc9316eaef..f3f64514a954a76cf8c61bd000f572eed0659714 100644 (file)
@@ -48,18 +48,18 @@ export default abstract class OCPPRequestService {
           // Reject it but keep the request in the cache
           return reject(ocppError);
         }
-        return rejectCallback(ocppError);
+        return rejectCallback(ocppError, false);
       } else {
         // Reject it
-        return rejectCallback(new OCPPError(ErrorType.GENERIC_ERROR, `WebSocket closed for non buffered message id '${messageId}' with content '${messageToSend}'`, commandParams?.details ?? {}));
+        return rejectCallback(new OCPPError(ErrorType.GENERIC_ERROR, `WebSocket closed for non buffered message id '${messageId}' with content '${messageToSend}'`, commandParams?.details ?? {}), false);
       }
       // Response?
       if (messageType !== MessageType.CALL_MESSAGE) {
         // Yes: send Ok
-        resolve({ commandName, commandParams });
+        resolve(commandParams);
       } else {
         // Send timeout
-        setTimeout(() => rejectCallback(new OCPPError(ErrorType.GENERIC_ERROR, `Timeout for message id '${messageId}' with content '${messageToSend}'`, commandParams?.details ?? {})), Constants.OCPP_SOCKET_TIMEOUT);
+        setTimeout(() => rejectCallback(new OCPPError(ErrorType.GENERIC_ERROR, `Timeout for message id '${messageId}' with content '${messageToSend}'`, commandParams?.details ?? {}), false), Constants.OCPP_SOCKET_TIMEOUT);
       }
 
       /**
@@ -75,16 +75,17 @@ export default abstract class OCPPRequestService {
         // Send the response
         await self.ocppResponseService.handleResponse(commandName as RequestCommand, payload, requestPayload);
         self.chargingStation.requests.delete(messageId);
-        resolve({ commandName, payload, requestPayload });
+        resolve(payload);
       }
 
       /**
        * Function that will receive the request's error response
        *
        * @param error
+       * @param requestStatistic
        */
-      function rejectCallback(error: OCPPError): void {
-        if (self.chargingStation.getEnableStatistics()) {
+      function rejectCallback(error: OCPPError, requestStatistic = true): void {
+        if (requestStatistic && self.chargingStation.getEnableStatistics()) {
           self.chargingStation.performanceStatistics.addRequestStatistic(commandName, MessageType.CALL_ERROR_MESSAGE);
         }
         logger.error(`${self.chargingStation.logPrefix()} Error %j occurred when calling command %s with parameters %j`, error, commandName, commandParams);