From e64c092349ce9744ed017cfa757dc0b86bff5fd5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 13 Aug 2021 23:03:40 +0200 Subject: [PATCH] Fix error handling of incoming OCPP request MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .../ocpp/1.6/OCCP16IncomingRequestService.ts | 3 +-- src/charging-station/ocpp/OCPPIncomingRequestService.ts | 5 ++++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/charging-station/ocpp/1.6/OCCP16IncomingRequestService.ts b/src/charging-station/ocpp/1.6/OCCP16IncomingRequestService.ts index 40f80a2c..4dc5ed66 100644 --- a/src/charging-station/ocpp/1.6/OCCP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCCP16IncomingRequestService.ts @@ -385,11 +385,10 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer throw new Error(`Diagnostics transfer failed with error code ${accessResponse.code.toString()}${uploadResponse?.code && '|' + uploadResponse?.code.toString()}`); } catch (error) { await this.chargingStation.ocppRequestService.sendDiagnosticsStatusNotification(OCPP16DiagnosticsStatus.UploadFailed); - this.handleIncomingRequestError(IncomingRequestCommand.GET_DIAGNOSTICS, error); if (ftpClient) { ftpClient.close(); } - return Constants.OCPP_RESPONSE_EMPTY; + return this.handleIncomingRequestError(IncomingRequestCommand.GET_DIAGNOSTICS, error, Constants.OCPP_RESPONSE_EMPTY); } } else { logger.error(`${this.chargingStation.logPrefix()} Unsupported protocol ${uri.protocol} to transfer the diagnostic logs archive`); diff --git a/src/charging-station/ocpp/OCPPIncomingRequestService.ts b/src/charging-station/ocpp/OCPPIncomingRequestService.ts index 9980e5d8..ff2dfd4c 100644 --- a/src/charging-station/ocpp/OCPPIncomingRequestService.ts +++ b/src/charging-station/ocpp/OCPPIncomingRequestService.ts @@ -9,8 +9,11 @@ export default abstract class OCPPIncomingRequestService { this.chargingStation = chargingStation; } - public handleIncomingRequestError(commandName: IncomingRequestCommand, error: Error): void { + public handleIncomingRequestError(commandName: IncomingRequestCommand, error: Error, ocppResponse?): unknown { logger.error(this.chargingStation.logPrefix() + ' Incoming request command ' + commandName + ' error: %j', error); + if (ocppResponse) { + return ocppResponse; + } throw error; } -- 2.34.1