From: Jérôme Benoit Date: Fri, 13 Aug 2021 21:03:40 +0000 (+0200) Subject: Fix error handling of incoming OCPP request X-Git-Tag: v1.0.34~3 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=e64c092349ce9744ed017cfa757dc0b86bff5fd5;p=e-mobility-charging-stations-simulator.git Fix error handling of incoming OCPP request Signed-off-by: Jérôme Benoit --- 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; }