From: Jérôme Benoit Date: Sat, 27 May 2023 13:57:56 +0000 (+0200) Subject: fix: do not send UI protocol response if no handler is found X-Git-Tag: v1.2.15~31 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=1ca4a038d1b263b3b66a3c1872742bd98a696e75;p=e-mobility-charging-stations-simulator.git fix: do not send UI protocol response if no handler is found Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ui-server/AbstractUIServer.ts b/src/charging-station/ui-server/AbstractUIServer.ts index 8552a572..c21185fe 100644 --- a/src/charging-station/ui-server/AbstractUIServer.ts +++ b/src/charging-station/ui-server/AbstractUIServer.ts @@ -52,6 +52,10 @@ export abstract class AbstractUIServer { return this.uiServices.get(protocolVersion)?.requestHandler(request); } + public hasResponseHandler(uuid: string): boolean { + return this.responseHandlers.has(uuid); + } + protected startHttpServer(): void { if (this.httpServer.listening === false) { this.httpServer.listen(this.uiServerConfiguration.options); diff --git a/src/charging-station/ui-server/UIHttpServer.ts b/src/charging-station/ui-server/UIHttpServer.ts index ccafb084..159559df 100644 --- a/src/charging-station/ui-server/UIHttpServer.ts +++ b/src/charging-station/ui-server/UIHttpServer.ts @@ -44,7 +44,7 @@ export class UIHttpServer extends AbstractUIServer { public sendResponse(response: ProtocolResponse): void { const [uuid, payload] = response; try { - if (this.responseHandlers.has(uuid) === true) { + if (this.hasResponseHandler(uuid) === true) { const res = this.responseHandlers.get(uuid) as ServerResponse; res .writeHead(this.responseStatusToStatusCode(payload.status), { diff --git a/src/charging-station/ui-server/UIWebSocketServer.ts b/src/charging-station/ui-server/UIWebSocketServer.ts index 5ddf0e59..dd5b6163 100644 --- a/src/charging-station/ui-server/UIWebSocketServer.ts +++ b/src/charging-station/ui-server/UIWebSocketServer.ts @@ -112,7 +112,7 @@ export class UIWebSocketServer extends AbstractUIServer { public sendResponse(response: ProtocolResponse): void { const responseId = response[0]; try { - if (this.responseHandlers.has(responseId)) { + if (this.hasResponseHandler(responseId)) { const ws = this.responseHandlers.get(responseId) as WebSocket; if (ws?.readyState === WebSocket.OPEN) { ws.send(JSON.stringify(response)); diff --git a/src/charging-station/ui-server/ui-services/AbstractUIService.ts b/src/charging-station/ui-server/ui-services/AbstractUIService.ts index 0531011f..1ec6cf93 100644 --- a/src/charging-station/ui-server/ui-services/AbstractUIService.ts +++ b/src/charging-station/ui-server/ui-services/AbstractUIService.ts @@ -116,7 +116,9 @@ export abstract class AbstractUIService { // } public sendResponse(messageId: string, responsePayload: ResponsePayload): void { - this.uiServer.sendResponse(this.uiServer.buildProtocolResponse(messageId, responsePayload)); + if (this.uiServer.hasResponseHandler(messageId)) { + this.uiServer.sendResponse(this.uiServer.buildProtocolResponse(messageId, responsePayload)); + } } public logPrefix = (modName: string, methodName: string): string => {