refactor: improve OCPP error defaults and usage
[e-mobility-charging-stations-simulator.git] / src / charging-station / ui-server / UIServerUtils.ts
index cada139961dd0044686074eecbb158a0b6c16e7e..95bbba56c8134dd93f20ebbf2dcf06986e70961d 100644 (file)
@@ -11,10 +11,10 @@ export class UIServerUtils {
   public static handleProtocols = (
     protocols: Set<string>,
     // eslint-disable-next-line @typescript-eslint/no-unused-vars
-    request: IncomingMessage
+    request: IncomingMessage,
   ): string | false => {
-    let protocol: Protocol;
-    let version: ProtocolVersion;
+    let protocol: Protocol | undefined;
+    let version: ProtocolVersion | undefined;
     if (protocols.size === 0) {
       return false;
     }
@@ -25,8 +25,8 @@ export class UIServerUtils {
     }
     logger.error(
       `${logPrefix(
-        ' UI WebSocket Server |'
-      )} Unsupported protocol: ${protocol} or protocol version: ${version}`
+        ' UI WebSocket Server |',
+      )} Unsupported protocol: '${protocol}' or protocol version: '${version}'`,
     );
     return false;
   };
@@ -43,7 +43,7 @@ export class UIServerUtils {
     const protocolIndex = protocolStr.indexOf(Protocol.UI);
     const protocol = protocolStr.substring(
       protocolIndex,
-      protocolIndex + Protocol.UI.length
+      protocolIndex + Protocol.UI.length,
     ) as Protocol;
     const version = protocolStr.substring(protocolIndex + Protocol.UI.length) as ProtocolVersion;
     return [protocol, version];
@@ -53,7 +53,7 @@ export class UIServerUtils {
     const isLoopbackRegExp = new RegExp(
       // eslint-disable-next-line no-useless-escape
       /^localhost$|^127(?:\.\d+){0,2}\.\d+$|^(?:0*\:)*?:?0*1$/,
-      'i'
+      'i',
     );
     return isLoopbackRegExp.test(address);
   }