docs: fix README.md formatting
[e-mobility-charging-stations-simulator.git] / src / charging-station / ocpp / 1.6 / OCPP16ResponseService.ts
index 11be84936caf98fd77ab3306910a2108dc3d55cf..691bf0f6c6b243465255c2c4f322c1c65917ffb8 100644 (file)
@@ -51,7 +51,7 @@ import {
   type SetChargingProfileResponse,
   type UnlockConnectorResponse
 } from '../../../types/index.js'
-import { Constants, convertToInt, logger } from '../../../utils/index.js'
+import { Constants, convertToInt, isAsyncFunction, logger } from '../../../utils/index.js'
 import { OCPPResponseService } from '../OCPPResponseService.js'
 
 const moduleName = 'OCPP16ResponseService'
@@ -445,7 +445,18 @@ export class OCPP16ResponseService extends OCPPResponseService {
         try {
           this.validatePayload(chargingStation, commandName, payload)
           // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-          await this.responseHandlers.get(commandName)!(chargingStation, payload, requestPayload)
+          const responseHandler = this.responseHandlers.get(commandName)!
+          if (isAsyncFunction(responseHandler)) {
+            await responseHandler(chargingStation, payload, requestPayload)
+          } else {
+            (
+              responseHandler as (
+                chargingStation: ChargingStation,
+                payload: JsonType,
+                requestPayload?: JsonType
+              ) => void
+            )(chargingStation, payload, requestPayload)
+          }
         } catch (error) {
           logger.error(
             `${chargingStation.logPrefix()} ${moduleName}.responseHandler: Handle response error:`,
@@ -473,7 +484,7 @@ export class OCPP16ResponseService extends OCPPResponseService {
           payload,
           undefined,
           2
-        )} while the charging station is not registered on the central server.`,
+        )} while the charging station is not registered on the central server`,
         commandName,
         payload
       )
@@ -574,7 +585,7 @@ export class OCPP16ResponseService extends OCPPResponseService {
         logger.debug(
           `${chargingStation.logPrefix()} idTag '${requestPayload.idTag}' rejected with status '${
             payload.idTagInfo.status
-          }`
+          }'`
         )
       }
     } else {