- public async handleRequest(messageId: string, commandName: OCPP16IncomingRequestCommand, commandPayload: Record<string, unknown>): Promise<void> {
- let response: Record<string, unknown>;
- if (this.incomingRequestHandlers.has(commandName)) {
- try {
- // Call the method to build the response
- response = await this.incomingRequestHandlers.get(commandName)(commandPayload);
- } catch (error) {
- // Log
- logger.error(this.chargingStation.logPrefix() + ' Handle request error: %j', error);
- throw error;
+ public async handleRequest(messageId: string, commandName: OCPP16IncomingRequestCommand, commandPayload: JsonType): Promise<void> {
+ let result: JsonType;
+ if (this.chargingStation.getOcppStrictCompliance() && (this.chargingStation.isInPendingState()
+ && (commandName === OCPP16IncomingRequestCommand.REMOTE_START_TRANSACTION || commandName === OCPP16IncomingRequestCommand.REMOTE_STOP_TRANSACTION))) {
+ throw new OCPPError(ErrorType.SECURITY_ERROR, `${commandName} cannot be issued to handle request payload ${JSON.stringify(commandPayload, null, 2)} while the charging station is in pending state on the central server`, commandName);
+ }
+ if (this.chargingStation.isRegistered() || (!this.chargingStation.getOcppStrictCompliance() && this.chargingStation.isInUnknownState())) {
+ if (this.incomingRequestHandlers.has(commandName)) {
+ try {
+ // Call the method to build the result
+ result = await this.incomingRequestHandlers.get(commandName)(commandPayload);
+ } catch (error) {
+ // Log
+ logger.error(this.chargingStation.logPrefix() + ' Handle request error: %j', error);
+ throw error;
+ }
+ } else {
+ // Throw exception
+ throw new OCPPError(ErrorType.NOT_IMPLEMENTED, `${commandName} is not implemented to handle request payload ${JSON.stringify(commandPayload, null, 2)}`, commandName);