From: Jérôme Benoit Date: Sat, 26 Nov 2022 20:55:49 +0000 (+0100) Subject: Fix OCPP response handling synchronicity X-Git-Tag: v1.1.88~15 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=3a148e4826715d4125498f60b35c23c3962970ab;p=e-mobility-charging-stations-simulator.git Fix OCPP response handling synchronicity Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ocpp/OCPPRequestService.ts b/src/charging-station/ocpp/OCPPRequestService.ts index 29c740a1..bdfffc37 100644 --- a/src/charging-station/ocpp/OCPPRequestService.ts +++ b/src/charging-station/ocpp/OCPPRequestService.ts @@ -234,10 +234,7 @@ export default abstract class OCPPRequestService { * @param payload * @param requestPayload */ - async function responseCallback( - payload: JsonType, - requestPayload: JsonType - ): Promise { + function responseCallback(payload: JsonType, requestPayload: JsonType): void { if (chargingStation.getEnableStatistics() === true) { chargingStation.performanceStatistics.addRequestStatistic( commandName, @@ -245,19 +242,22 @@ export default abstract class OCPPRequestService { ); } // Handle the request's response - try { - await self.ocppResponseService.responseHandler( + self.ocppResponseService + .responseHandler( chargingStation, commandName as RequestCommand, payload, requestPayload - ); - resolve(payload); - } catch (error) { - reject(error); - } finally { - chargingStation.requests.delete(messageId); - } + ) + .then(() => { + resolve(payload); + }) + .catch((error) => { + reject(error); + }) + .finally(() => { + chargingStation.requests.delete(messageId); + }); } /** @@ -308,7 +308,7 @@ export default abstract class OCPPRequestService { messagePayload: JsonType | OCPPError, messageType: MessageType, commandName?: RequestCommand | IncomingRequestCommand, - responseCallback?: (payload: JsonType, requestPayload: JsonType) => Promise, + responseCallback?: (payload: JsonType, requestPayload: JsonType) => void, errorCallback?: (error: OCPPError, requestStatistic?: boolean) => void ): string { let messageToSend: string;