Use generics for incoming message error handling
authorJérôme Benoit <jerome.benoit@sap.com>
Sun, 5 Sep 2021 17:56:05 +0000 (19:56 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Sun, 5 Sep 2021 17:56:05 +0000 (19:56 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts
src/charging-station/ocpp/OCPPIncomingRequestService.ts

index 541a27fb631584efdc6a78aa7142b408e70ec672..7fde148b4834af16a4428345cc745661536eefb8 100644 (file)
@@ -419,7 +419,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
           return Constants.OCPP_TRIGGER_MESSAGE_RESPONSE_NOT_IMPLEMENTED;
       }
     } catch (error) {
-      return this.handleIncomingRequestError(IncomingRequestCommand.TRIGGER_MESSAGE, error, Constants.OCPP_TRIGGER_MESSAGE_RESPONSE_REJECTED) as OCPP16TriggerMessageResponse;
+      return this.handleIncomingRequestError(IncomingRequestCommand.TRIGGER_MESSAGE, error, Constants.OCPP_TRIGGER_MESSAGE_RESPONSE_REJECTED);
     }
   }
 }
index 7e2fa1894935f97ff2b598ca6884d45507096342..dcef40287f014d9de35a04a95fa022a013a9ae37 100644 (file)
@@ -9,7 +9,7 @@ export default abstract class OCPPIncomingRequestService {
     this.chargingStation = chargingStation;
   }
 
-  protected handleIncomingRequestError(commandName: IncomingRequestCommand, error: Error, errorOcppResponse?: Record<string, unknown>): unknown {
+  protected handleIncomingRequestError<T>(commandName: IncomingRequestCommand, error: Error, errorOcppResponse?: T): T {
     logger.error(this.chargingStation.logPrefix() + ' Incoming request command ' + commandName + ' error: %j', error);
     if (errorOcppResponse) {
       return errorOcppResponse;