refactor: factor out JSON schema validation function getter
[e-mobility-charging-stations-simulator.git] / src / charging-station / ui-server / UIWebSocketServer.ts
index 8306be0e76ddc6f0c19a20945717deef2c2ded56..e322ef8db9901889344e41f9b97d41d1616c7bb3 100644 (file)
@@ -60,9 +60,9 @@ export class UIWebSocketServer extends AbstractUIServer {
         this.uiServices
           .get(version)
           ?.requestHandler(request)
-          .then((protocolResponse: ProtocolResponse) => {
+          .then((protocolResponse?: ProtocolResponse) => {
             if (!isNullOrUndefined(protocolResponse)) {
-              this.sendResponse(protocolResponse);
+              this.sendResponse(protocolResponse!);
             }
           })
           .catch(Constants.EMPTY_FUNCTION);
@@ -118,7 +118,7 @@ export class UIWebSocketServer extends AbstractUIServer {
   }
 
   public sendResponse(response: ProtocolResponse): void {
-    const responseId = response[0];
+    const responseId = response?.[0];
     try {
       if (this.hasResponseHandler(responseId)) {
         const ws = this.responseHandlers.get(responseId) as WebSocket;
@@ -176,10 +176,12 @@ export class UIWebSocketServer extends AbstractUIServer {
     // logger.debug(
     //   `${this.logPrefix(
     //     moduleName,
-    //     'validateRawDataRequest'
-    //   )} Raw data received in string format: ${rawData.toString()}`
+    //     'validateRawDataRequest',
+    //     // eslint-disable-next-line @typescript-eslint/no-base-to-string
+    //   )} 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;
 
     if (Array.isArray(request) === false) {
@@ -201,7 +203,7 @@ export class UIWebSocketServer extends AbstractUIServer {
       return false;
     }
 
-    if (validateUUID(request[0]) === false) {
+    if (validateUUID(request?.[0]) === false) {
       logger.error(
         `${this.logPrefix(
           moduleName,