From 3febbc9f6498f7f5a6dc754a5fa687d112cc2c9b Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 20 Nov 2023 15:50:12 +0100 Subject: [PATCH] fix: do not log twice OCPP request sending error MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/charging-station/ocpp/OCPPRequestService.ts | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/charging-station/ocpp/OCPPRequestService.ts b/src/charging-station/ocpp/OCPPRequestService.ts index c24742d7..77e87f43 100644 --- a/src/charging-station/ocpp/OCPPRequestService.ts +++ b/src/charging-station/ocpp/OCPPRequestService.ts @@ -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}'`, -- 2.34.1