Improve resquest response error logging
authorJérôme Benoit <jerome.benoit@sap.com>
Sat, 2 Oct 2021 09:03:37 +0000 (11:03 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Sat, 2 Oct 2021 09:03:37 +0000 (11:03 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts
src/charging-station/ocpp/1.6/OCPP16ResponseService.ts

index 5609fe21776bd543a48cae8ccdd10cfb1a698e01..94f98e8b0843603eea1ea8e52f8d28b85ad1ed2e 100644 (file)
@@ -59,7 +59,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
       }
     } else {
       // Throw exception
-      throw new OCPPError(ErrorType.NOT_IMPLEMENTED, `${commandName} is not implemented to handle payload ${JSON.stringify(commandPayload, null, 2)}`, commandName);
+      throw new OCPPError(ErrorType.NOT_IMPLEMENTED, `${commandName} is not implemented to handle request payload ${JSON.stringify(commandPayload, null, 2)}`, commandName);
     }
     // Send the built response
     await this.chargingStation.ocppRequestService.sendMessage(messageId, response, MessageType.CALL_RESULT_MESSAGE, commandName);
index 77c7b77a091b0a7864fb61d4b0eaa603437bb6fc..cc334aee41c4c67426236d9d429301c04143816f 100644 (file)
@@ -32,9 +32,13 @@ export default class OCPP16ResponseService extends OCPPResponseService {
 
   public async handleResponse(commandName: OCPP16RequestCommand, payload: Record<string, unknown> | string, requestPayload: Record<string, unknown>): Promise<void> {
     if (this.responseHandlers.has(commandName)) {
-      await this.responseHandlers.get(commandName)(payload, requestPayload);
+      try {
+        await this.responseHandlers.get(commandName)(payload, requestPayload);
+      } catch (error) {
+        logger.error(this.chargingStation.logPrefix() + ' Handle request response error: %j', error);
+      }
     } else {
-      logger.error(this.chargingStation.logPrefix() + ' Trying to call an undefined method for command ' + commandName + ' response');
+      logger.error(`${this.chargingStation.logPrefix()} %s is not implemented to handle request response payload %j`, commandName, payload);
     }
   }