refactor: remove unneeded try {} catch {}
authorJérôme Benoit <jerome.benoit@sap.com>
Mon, 29 Jan 2024 17:41:56 +0000 (18:41 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Mon, 29 Jan 2024 17:41:56 +0000 (18:41 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/Bootstrap.ts
src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts

index f09864d4ed66d935960084061359fe6ca7af3799..00926e4fd8860dc35a513645253c6cdfcbc646fe 100644 (file)
@@ -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)
index 7f932cb0e19165e65899f8265f5f7763ce415821..2af366f9cfbd4ac6945dc6262352e8493a3c98eb 100644 (file)
@@ -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<OCPP16TriggerMessageResponse>(
-        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
     }
   }