Vue UI + UI server
[e-mobility-charging-stations-simulator.git] / src / charging-station / ocpp / 1.6 / OCPP16IncomingRequestService.ts
index 3238722568d9cc92bae51cd1476a1e90a10d0b77..b785db03574aaf6afcd10dea5676533153d0a56e 100644 (file)
@@ -276,6 +276,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
         ) as JSONSchemaType<OCPP16TriggerMessageRequest>,
       ],
     ]);
+    this.validatePayload.bind(this);
   }
 
   public async incomingRequestHandler(
@@ -311,18 +312,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
         ChargingStationUtils.isIncomingRequestCommandSupported(commandName, chargingStation)
       ) {
         try {
-          if (this.jsonSchemas.has(commandName)) {
-            this.validateIncomingRequestPayload(
-              chargingStation,
-              commandName,
-              this.jsonSchemas.get(commandName),
-              commandPayload
-            );
-          } else {
-            logger.warn(
-              `${chargingStation.logPrefix()} ${moduleName}.incomingRequestHandler: No JSON schema found for command ${commandName} PDU validation`
-            );
-          }
+          this.validatePayload(chargingStation, commandName, commandPayload);
           // Call the method to build the response
           response = await this.incomingRequestHandlers.get(commandName)(
             chargingStation,
@@ -330,7 +320,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
           );
         } catch (error) {
           // Log
-          logger.error(chargingStation.logPrefix() + ' Handle request error: %j', error);
+          logger.error(chargingStation.logPrefix() + ' Handle request error:', error);
           throw error;
         }
       } else {
@@ -367,6 +357,25 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
     );
   }
 
+  private validatePayload(
+    chargingStation: ChargingStation,
+    commandName: OCPP16IncomingRequestCommand,
+    commandPayload: JsonType
+  ): boolean {
+    if (this.jsonSchemas.has(commandName)) {
+      return this.validateIncomingRequestPayload(
+        chargingStation,
+        commandName,
+        this.jsonSchemas.get(commandName),
+        commandPayload
+      );
+    }
+    logger.warn(
+      `${chargingStation.logPrefix()} ${moduleName}.validatePayload: No JSON schema found for command ${commandName} PDU validation`
+    );
+    return false;
+  }
+
   // Simulate charging station restart
   private handleRequestReset(
     chargingStation: ChargingStation,