From f2f33b97eb2044a8c715ebe0c0eb1c7b973eb8c4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 29 Jan 2024 18:41:56 +0100 Subject: [PATCH] refactor: remove unneeded try {} catch {} MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/charging-station/Bootstrap.ts | 2 +- .../ocpp/1.6/OCPP16IncomingRequestService.ts | 58 ++++++++----------- 2 files changed, 24 insertions(+), 36 deletions(-) diff --git a/src/charging-station/Bootstrap.ts b/src/charging-station/Bootstrap.ts index f09864d4..00926e4f 100644 --- a/src/charging-station/Bootstrap.ts +++ b/src/charging-station/Bootstrap.ts @@ -311,7 +311,7 @@ export class Bootstrap extends EventEmitter { break case ChargingStationWorkerMessageEvents.startWorkerElementError: logger.error( - `${this.logPrefix()} ${moduleName}.messageHandler: Error occured while starting worker element:`, + `${this.logPrefix()} ${moduleName}.messageHandler: Error occurred while starting worker element:`, msg.data ) this.emit(ChargingStationWorkerMessageEvents.startWorkerElementError, msg.data) diff --git a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts index 7f932cb0..2af366f9 100644 --- a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts @@ -1553,42 +1553,30 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService { ) { return OCPP16Constants.OCPP_TRIGGER_MESSAGE_RESPONSE_REJECTED } - try { - switch (requestedMessage) { - case OCPP16MessageTrigger.BootNotification: - Promise.resolve() - .then(() => - this.emit(`Trigger${OCPP16MessageTrigger.BootNotification}`, chargingStation) - ) - .catch(Constants.EMPTY_FUNCTION) - return OCPP16Constants.OCPP_TRIGGER_MESSAGE_RESPONSE_ACCEPTED - case OCPP16MessageTrigger.Heartbeat: - Promise.resolve() - .then(() => this.emit(`Trigger${OCPP16MessageTrigger.Heartbeat}`, chargingStation)) - .catch(Constants.EMPTY_FUNCTION) - return OCPP16Constants.OCPP_TRIGGER_MESSAGE_RESPONSE_ACCEPTED - case OCPP16MessageTrigger.StatusNotification: - Promise.resolve() - .then(() => - this.emit( - `Trigger${OCPP16MessageTrigger.StatusNotification}`, - chargingStation, - connectorId - ) + switch (requestedMessage) { + case OCPP16MessageTrigger.BootNotification: + Promise.resolve() + .then(() => this.emit(`Trigger${OCPP16MessageTrigger.BootNotification}`, chargingStation)) + .catch(Constants.EMPTY_FUNCTION) + return OCPP16Constants.OCPP_TRIGGER_MESSAGE_RESPONSE_ACCEPTED + case OCPP16MessageTrigger.Heartbeat: + Promise.resolve() + .then(() => this.emit(`Trigger${OCPP16MessageTrigger.Heartbeat}`, chargingStation)) + .catch(Constants.EMPTY_FUNCTION) + return OCPP16Constants.OCPP_TRIGGER_MESSAGE_RESPONSE_ACCEPTED + case OCPP16MessageTrigger.StatusNotification: + Promise.resolve() + .then(() => + this.emit( + `Trigger${OCPP16MessageTrigger.StatusNotification}`, + chargingStation, + connectorId ) - .catch(Constants.EMPTY_FUNCTION) - return OCPP16Constants.OCPP_TRIGGER_MESSAGE_RESPONSE_ACCEPTED - default: - return OCPP16Constants.OCPP_TRIGGER_MESSAGE_RESPONSE_NOT_IMPLEMENTED - } - } catch (error) { - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - return this.handleIncomingRequestError( - chargingStation, - OCPP16IncomingRequestCommand.TRIGGER_MESSAGE, - error as Error, - { errorResponse: OCPP16Constants.OCPP_TRIGGER_MESSAGE_RESPONSE_REJECTED } - )! + ) + .catch(Constants.EMPTY_FUNCTION) + return OCPP16Constants.OCPP_TRIGGER_MESSAGE_RESPONSE_ACCEPTED + default: + return OCPP16Constants.OCPP_TRIGGER_MESSAGE_RESPONSE_NOT_IMPLEMENTED } } -- 2.34.1