Fix error propagation into the UI server
authorJérôme Benoit <jerome.benoit@sap.com>
Mon, 9 Jan 2023 15:48:31 +0000 (16:48 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Mon, 9 Jan 2023 15:48:31 +0000 (16:48 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ChargingStationWorkerBroadcastChannel.ts
src/charging-station/ocpp/OCPPRequestService.ts
src/types/ocpp/Requests.ts

index 1528d65c0983580e86fb99b7e0b0f314612dd7a7..1c7121ecc7f54b731655afc1c0f499445ae72973 100644 (file)
@@ -9,6 +9,7 @@ import {
   type HeartbeatRequest,
   type MeterValuesRequest,
   RequestCommand,
+  RequestParams,
   type StatusNotificationRequest,
 } from '../types/ocpp/Requests';
 import {
@@ -71,6 +72,9 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca
 
   constructor(chargingStation: ChargingStation) {
     super();
+    const requestParams: RequestParams = {
+      throwError: true,
+    };
     this.commandHandlers = new Map<BroadcastChannelProcedureName, CommandHandler>([
       [BroadcastChannelProcedureName.START_CHARGING_STATION, () => this.chargingStation.start()],
       [
@@ -101,7 +105,7 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca
           this.chargingStation.ocppRequestService.requestHandler<
             StartTransactionRequest,
             StartTransactionResponse
-          >(this.chargingStation, RequestCommand.START_TRANSACTION, requestPayload),
+          >(this.chargingStation, RequestCommand.START_TRANSACTION, requestPayload, requestParams),
       ],
       [
         BroadcastChannelProcedureName.STOP_TRANSACTION,
@@ -115,6 +119,7 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca
               true
             ),
             ...requestPayload,
+            requestParams,
           }),
       ],
       [
@@ -123,7 +128,7 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca
           this.chargingStation.ocppRequestService.requestHandler<
             AuthorizeRequest,
             AuthorizeResponse
-          >(this.chargingStation, RequestCommand.AUTHORIZE, requestPayload),
+          >(this.chargingStation, RequestCommand.AUTHORIZE, requestPayload, requestParams),
       ],
       [
         BroadcastChannelProcedureName.BOOT_NOTIFICATION,
@@ -141,6 +146,7 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca
               },
               {
                 skipBufferingOnError: true,
+                throwError: true,
               }
             );
           return this.chargingStation.bootNotificationResponse;
@@ -152,7 +158,12 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca
           this.chargingStation.ocppRequestService.requestHandler<
             StatusNotificationRequest,
             StatusNotificationResponse
-          >(this.chargingStation, RequestCommand.STATUS_NOTIFICATION, requestPayload),
+          >(
+            this.chargingStation,
+            RequestCommand.STATUS_NOTIFICATION,
+            requestPayload,
+            requestParams
+          ),
       ],
       [
         BroadcastChannelProcedureName.HEARTBEAT,
@@ -160,7 +171,7 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca
           this.chargingStation.ocppRequestService.requestHandler<
             HeartbeatRequest,
             HeartbeatResponse
-          >(this.chargingStation, RequestCommand.HEARTBEAT, requestPayload),
+          >(this.chargingStation, RequestCommand.HEARTBEAT, requestPayload, requestParams),
       ],
       [
         BroadcastChannelProcedureName.METER_VALUES,
@@ -185,6 +196,7 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca
               ),
             ],
             ...requestPayload,
+            requestParams,
           });
         },
       ],
@@ -194,7 +206,7 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca
           this.chargingStation.ocppRequestService.requestHandler<
             DataTransferRequest,
             DataTransferResponse
-          >(this.chargingStation, RequestCommand.DATA_TRANSFER, requestPayload),
+          >(this.chargingStation, RequestCommand.DATA_TRANSFER, requestPayload, requestParams),
       ],
       [
         BroadcastChannelProcedureName.DIAGNOSTICS_STATUS_NOTIFICATION,
@@ -202,7 +214,12 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca
           this.chargingStation.ocppRequestService.requestHandler<
             DiagnosticsStatusNotificationRequest,
             DiagnosticsStatusNotificationResponse
-          >(this.chargingStation, RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION, requestPayload),
+          >(
+            this.chargingStation,
+            RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION,
+            requestPayload,
+            requestParams
+          ),
       ],
       [
         BroadcastChannelProcedureName.FIRMWARE_STATUS_NOTIFICATION,
@@ -210,7 +227,12 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca
           this.chargingStation.ocppRequestService.requestHandler<
             FirmwareStatusNotificationRequest,
             FirmwareStatusNotificationResponse
-          >(this.chargingStation, RequestCommand.FIRMWARE_STATUS_NOTIFICATION, requestPayload),
+          >(
+            this.chargingStation,
+            RequestCommand.FIRMWARE_STATUS_NOTIFICATION,
+            requestPayload,
+            requestParams
+          ),
       ],
     ]);
     this.chargingStation = chargingStation;
index 0d95ffa5493f8f4b06677c43f7cf47231ff9ee30..aba9bfd00edc28949779c23eaac079f116324ca6 100644 (file)
@@ -113,6 +113,7 @@ export default abstract class OCPPRequestService {
     params: RequestParams = {
       skipBufferingOnError: false,
       triggerMessage: false,
+      throwError: false,
     }
   ): Promise<ResponseType> {
     try {
@@ -125,7 +126,9 @@ export default abstract class OCPPRequestService {
         params
       );
     } catch (error) {
-      this.handleSendMessageError(chargingStation, commandName, error as Error);
+      this.handleSendMessageError(chargingStation, commandName, error as Error, {
+        throwError: params.throwError,
+      });
     }
   }
 
index 884da269e5e863c30082c6a04a22bb35653d0778..993ba086a2d62ffd5e1bf6728787548743eedf46 100644 (file)
@@ -34,6 +34,7 @@ export type OutgoingRequest = [MessageType.CALL_MESSAGE, string, RequestCommand,
 export type RequestParams = {
   skipBufferingOnError?: boolean;
   triggerMessage?: boolean;
+  throwError?: boolean;
 };
 
 export const IncomingRequestCommand = {