From 887fef764941b7a9970fd78bbc608882c320fe78 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sat, 2 Oct 2021 11:03:37 +0200 Subject: [PATCH] Improve resquest response error logging MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .../ocpp/1.6/OCPP16IncomingRequestService.ts | 2 +- src/charging-station/ocpp/1.6/OCPP16ResponseService.ts | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts index 5609fe21..94f98e8b 100644 --- a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts @@ -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); diff --git a/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts b/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts index 77c7b77a..cc334aee 100644 --- a/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts @@ -32,9 +32,13 @@ export default class OCPP16ResponseService extends OCPPResponseService { public async handleResponse(commandName: OCPP16RequestCommand, payload: Record | string, requestPayload: Record): Promise { 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); } } -- 2.34.1