X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fcharging-station%2Fui-server%2FUIHttpServer.ts;h=eafea59ad3ec2398be9f1e4c2c526e829c7e98d2;hb=3000c1258ccda0c8828f4e4fffb988e5ffaa84da;hp=27e8d7ba9051654d777f904b7e5ff16c884b0a47;hpb=a66bbcfe85550dc01a2e32bd17a52f5980a78193;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ui-server/UIHttpServer.ts b/src/charging-station/ui-server/UIHttpServer.ts index 27e8d7ba..eafea59a 100644 --- a/src/charging-station/ui-server/UIHttpServer.ts +++ b/src/charging-station/ui-server/UIHttpServer.ts @@ -126,10 +126,22 @@ export class UIHttpServer extends AbstractUIServer { bodyBuffer.push(chunk) }) .on('end', () => { - const body = JSON.parse(Buffer.concat(bodyBuffer).toString()) as RequestPayload + let requestPayload: RequestPayload | undefined + try { + requestPayload = JSON.parse(Buffer.concat(bodyBuffer).toString()) as RequestPayload + } catch (error) { + this.sendResponse( + this.buildProtocolResponse(uuid, { + status: ResponseStatus.FAILURE, + errorMessage: (error as Error).message, + errorStack: (error as Error).stack + }) + ) + return + } this.uiServices .get(version) - ?.requestHandler(this.buildProtocolRequest(uuid, procedureName, body)) + ?.requestHandler(this.buildProtocolRequest(uuid, procedureName, requestPayload)) .then((protocolResponse?: ProtocolResponse) => { if (protocolResponse != null) { this.sendResponse(protocolResponse)