X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fcharging-station%2Focpp%2F2.0%2FOCPP20ResponseService.ts;h=ef0a0360bcf5e0a41e12452bc8c49ff020459f22;hb=412cece829a669e4e41d9e824fb71cab4df20312;hp=bb12b0069c7fedbab970755c629b984de486cab8;hpb=d5490a13c341153af159d4b2ed745d32dc38452f;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ocpp/2.0/OCPP20ResponseService.ts b/src/charging-station/ocpp/2.0/OCPP20ResponseService.ts index bb12b006..ef0a0360 100644 --- a/src/charging-station/ocpp/2.0/OCPP20ResponseService.ts +++ b/src/charging-station/ocpp/2.0/OCPP20ResponseService.ts @@ -19,7 +19,7 @@ import { RegistrationStatusEnumType, type ResponseHandler } from '../../../types/index.js' -import { logger } from '../../../utils/index.js' +import { isAsyncFunction, logger } from '../../../utils/index.js' import { OCPPResponseService } from '../OCPPResponseService.js' const moduleName = 'OCPP20ResponseService' @@ -118,7 +118,18 @@ export class OCPP20ResponseService 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:`, @@ -146,7 +157,7 @@ export class OCPP20ResponseService 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 )