fix(simulator): detect string emptyness properly
[e-mobility-charging-stations-simulator.git] / src / charging-station / ui-server / UIHttpServer.ts
index 223c5bbbff1664dc111b0e62508436c726168673..48dfadbdddc8f611ec5fd5150c6ffda83f8c1b41 100644 (file)
@@ -2,21 +2,21 @@ import type { IncomingMessage, RequestListener, ServerResponse } from 'http';
 
 import { StatusCodes } from 'http-status-codes';
 
+import { AbstractUIServer } from './AbstractUIServer';
+import { UIServerUtils } from './UIServerUtils';
 import BaseError from '../../exception/BaseError';
 import type { UIServerConfiguration } from '../../types/ConfigurationData';
 import {
-  ProcedureName,
-  Protocol,
-  ProtocolRequest,
-  ProtocolResponse,
-  ProtocolVersion,
-  RequestPayload,
+  type ProcedureName,
+  type Protocol,
+  type ProtocolRequest,
+  type ProtocolResponse,
+  type ProtocolVersion,
+  type RequestPayload,
   ResponseStatus,
 } from '../../types/UIProtocol';
 import logger from '../../utils/Logger';
 import Utils from '../../utils/Utils';
-import { AbstractUIServer } from './AbstractUIServer';
-import { UIServerUtils } from './UIServerUtils';
 
 const moduleName = 'UIHttpServer';
 
@@ -60,12 +60,14 @@ export default class UIHttpServer extends AbstractUIServer {
     }
   }
 
-  public logPrefix(modName?: string, methodName?: string, prefixSuffix?: string): string {
+  public logPrefix = (modName?: string, methodName?: string, prefixSuffix?: string): string => {
     const logMsgPrefix = prefixSuffix ? `UI HTTP Server ${prefixSuffix}` : 'UI HTTP Server';
     const logMsg =
-      modName && methodName ? ` ${logMsgPrefix} | ${modName}.${methodName}:` : ` ${logMsgPrefix} |`;
+      Utils.isNotEmptyString(modName) && Utils.isNotEmptyString(methodName)
+        ? ` ${logMsgPrefix} | ${modName}.${methodName}:`
+        : ` ${logMsgPrefix} |`;
     return Utils.logPrefix(logMsg);
-  }
+  };
 
   private requestListener(req: IncomingMessage, res: ServerResponse): void {
     this.authenticate(req, (err) => {
@@ -110,7 +112,7 @@ export default class UIHttpServer extends AbstractUIServer {
             const body = JSON.parse(Buffer.concat(bodyBuffer).toString()) as RequestPayload;
             this.uiServices
               .get(version)
-              .requestHandler(this.buildProtocolRequest(uuid, procedureName, body ?? {}))
+              ?.requestHandler(this.buildProtocolRequest(uuid, procedureName, body ?? {}))
               .catch(() => {
                 /* Error caught by AbstractUIService */
               });