From: Jérôme Benoit Date: Mon, 20 Nov 2023 21:27:55 +0000 (+0100) Subject: fix(simulator): buffer OCPP payload at sending error X-Git-Tag: v1.2.26~19 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=2b94ad12b41578109dd303bf77c49ff93ed2f7e5;p=e-mobility-charging-stations-simulator.git fix(simulator): buffer OCPP payload at sending error Closes #156 Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ocpp/OCPPRequestService.ts b/src/charging-station/ocpp/OCPPRequestService.ts index bb9a75fe..794f3e25 100644 --- a/src/charging-station/ocpp/OCPPRequestService.ts +++ b/src/charging-station/ocpp/OCPPRequestService.ts @@ -22,7 +22,13 @@ import { type ResponseCallback, type ResponseType, } from '../../types'; -import { cloneObject, handleSendMessageError, isNullOrUndefined, logger } from '../../utils'; +import { + cloneObject, + formatDurationMilliSeconds, + handleSendMessageError, + isNullOrUndefined, + logger, +} from '../../utils'; const moduleName = 'OCPPRequestService'; @@ -367,14 +373,6 @@ export abstract class OCPPRequestService { reject(ocppError); }; - const rejectAndCleanRequestsCache = (ocppError: OCPPError): void => { - // Remove request from the cache - if (messageType === MessageType.CALL_MESSAGE) { - chargingStation.requests.delete(messageId); - } - return reject(ocppError); - }; - const handleSendError = (ocppError: OCPPError): void => { if (params?.skipBufferingOnError === false) { // Buffer @@ -389,10 +387,11 @@ export abstract class OCPPRequestService { errorCallback, ); } - // Reject and keep request in the cache - return reject(ocppError); + } else if (messageType === MessageType.CALL_MESSAGE) { + // Remove request from the cache + chargingStation.requests.delete(messageId); } - return rejectAndCleanRequestsCache(ocppError); + return reject(ocppError); }; if (chargingStation.stationInfo?.enableStatistics === true) { @@ -409,10 +408,14 @@ export abstract class OCPPRequestService { if (chargingStation.isWebSocketConnectionOpened() === true) { const beginId = PerformanceStatistics.beginMeasure(commandName); const sendTimeout = setTimeout(() => { - return rejectAndCleanRequestsCache( + return handleSendError( new OCPPError( ErrorType.GENERIC_ERROR, - `Timeout for message id '${messageId}'`, + `Timeout ${formatDurationMilliSeconds( + OCPPConstants.OCPP_WEBSOCKET_TIMEOUT, + )} reached for ${ + params?.skipBufferingOnError === false ? '' : 'non ' + }buffered message id '${messageId}' with content '${messageToSend}`, commandName, (messagePayload as OCPPError).details, ),