From: Jérôme Benoit Date: Mon, 9 Jan 2023 15:48:31 +0000 (+0100) Subject: Fix error propagation into the UI server X-Git-Tag: v1.1.89~3 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=8ec8e3d00ee6b2dca0760dd77973e338ea5a23a7;p=e-mobility-charging-stations-simulator.git Fix error propagation into the UI server Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ChargingStationWorkerBroadcastChannel.ts b/src/charging-station/ChargingStationWorkerBroadcastChannel.ts index 1528d65c..1c7121ec 100644 --- a/src/charging-station/ChargingStationWorkerBroadcastChannel.ts +++ b/src/charging-station/ChargingStationWorkerBroadcastChannel.ts @@ -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.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; diff --git a/src/charging-station/ocpp/OCPPRequestService.ts b/src/charging-station/ocpp/OCPPRequestService.ts index 0d95ffa5..aba9bfd0 100644 --- a/src/charging-station/ocpp/OCPPRequestService.ts +++ b/src/charging-station/ocpp/OCPPRequestService.ts @@ -113,6 +113,7 @@ export default abstract class OCPPRequestService { params: RequestParams = { skipBufferingOnError: false, triggerMessage: false, + throwError: false, } ): Promise { 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, + }); } } diff --git a/src/types/ocpp/Requests.ts b/src/types/ocpp/Requests.ts index 884da269..993ba086 100644 --- a/src/types/ocpp/Requests.ts +++ b/src/types/ocpp/Requests.ts @@ -34,6 +34,7 @@ export type OutgoingRequest = [MessageType.CALL_MESSAGE, string, RequestCommand, export type RequestParams = { skipBufferingOnError?: boolean; triggerMessage?: boolean; + throwError?: boolean; }; export const IncomingRequestCommand = {