X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2Fui-server%2FUIWebSocketServer.ts;h=16477146f0c638fbd1776213df0d336e3fa9f62d;hb=a474cbe107fedbe17398e5d21f852f0ce0d5ca2f;hp=42162d16556c47cec0c0b7805f77fc36d3ac7f99;hpb=a974c8e4b8a98c9450be49546a77be0d03e9f512;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ui-server/UIWebSocketServer.ts b/src/charging-station/ui-server/UIWebSocketServer.ts index 42162d16..16477146 100644 --- a/src/charging-station/ui-server/UIWebSocketServer.ts +++ b/src/charging-station/ui-server/UIWebSocketServer.ts @@ -14,6 +14,7 @@ import { } from '../../types/index.js' import { Constants, + JSONStringifyWithMapSupport, getWebSocketCloseEventStatusString, isNotEmptyString, logPrefix, @@ -120,7 +121,7 @@ export class UIWebSocketServer extends AbstractUIServer { if (this.hasResponseHandler(responseId)) { const ws = this.responseHandlers.get(responseId) as WebSocket if (ws.readyState === WebSocket.OPEN) { - ws.send(JSON.stringify(response)) + ws.send(JSONStringifyWithMapSupport(response)) } else { logger.error( `${this.logPrefix( @@ -179,8 +180,20 @@ export class UIWebSocketServer extends AbstractUIServer { // )} Raw data received in string format: ${rawData.toString()}` // ) - // eslint-disable-next-line @typescript-eslint/no-base-to-string - const request = JSON.parse(rawData.toString()) as ProtocolRequest + let request: ProtocolRequest + try { + // eslint-disable-next-line @typescript-eslint/no-base-to-string + request = JSON.parse(rawData.toString()) as ProtocolRequest + } catch (error) { + logger.error( + `${this.logPrefix( + moduleName, + 'validateRawDataRequest' + // eslint-disable-next-line @typescript-eslint/no-base-to-string + )} UI protocol request is not valid JSON: ${rawData.toString()}` + ) + return false + } if (!Array.isArray(request)) { logger.error(