X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2Focpp%2FOCPPRequestService.ts;h=a3b78ca63ec8e40d44a07c7a12f9689ed38eee63;hb=933e253b07b60f598e94a40cb817e334fb0f1995;hp=30e4a4a867fdc1f458bea1544e6d91c0517539cf;hpb=4c3c0d59f56be4d58e906e938c00390b41e0ca7f;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ocpp/OCPPRequestService.ts b/src/charging-station/ocpp/OCPPRequestService.ts index 30e4a4a8..a3b78ca6 100644 --- a/src/charging-station/ocpp/OCPPRequestService.ts +++ b/src/charging-station/ocpp/OCPPRequestService.ts @@ -6,14 +6,11 @@ import type { OCPPResponseService } from './OCPPResponseService'; import { OCPPServiceUtils } from './OCPPServiceUtils'; import type { ChargingStation } from '../../charging-station'; import { OCPPError } from '../../exception'; -// import { PerformanceStatistics } from '../../performance'; -import { PerformanceStatistics } from '../../performance/PerformanceStatistics'; +import { PerformanceStatistics } from '../../performance'; import { - type EmptyObject, type ErrorCallback, type ErrorResponse, ErrorType, - type HandleErrorParams, type IncomingRequestCommand, type JsonObject, type JsonType, @@ -26,10 +23,16 @@ import { type ResponseCallback, type ResponseType, } from '../../types'; -import { Constants, Utils, logger } from '../../utils'; +import { Constants, Utils, handleSendMessageError, logger } from '../../utils'; const moduleName = 'OCPPRequestService'; +const defaultRequestParams: RequestParams = { + skipBufferingOnError: false, + triggerMessage: false, + throwError: false, +}; + export abstract class OCPPRequestService { private static instance: OCPPRequestService | null = null; private readonly version: OCPPVersion; @@ -130,7 +133,7 @@ export abstract class OCPPRequestService { commandName ); } catch (error) { - this.handleSendMessageError(chargingStation, commandName, error as Error, { + handleSendMessageError(chargingStation, commandName, error as Error, { throwError: true, }); } @@ -152,7 +155,7 @@ export abstract class OCPPRequestService { commandName ); } catch (error) { - this.handleSendMessageError(chargingStation, commandName, error as Error); + handleSendMessageError(chargingStation, commandName, error as Error); } } @@ -161,12 +164,12 @@ export abstract class OCPPRequestService { messageId: string, messagePayload: JsonType, commandName: RequestCommand, - params: RequestParams = { - skipBufferingOnError: false, - triggerMessage: false, - throwError: false, - } + params: RequestParams = defaultRequestParams ): Promise { + params = { + ...defaultRequestParams, + ...params, + }; try { return await this.internalSendMessage( chargingStation, @@ -177,7 +180,7 @@ export abstract class OCPPRequestService { params ); } catch (error) { - this.handleSendMessageError(chargingStation, commandName, error as Error, { + handleSendMessageError(chargingStation, commandName, error as Error, { throwError: params.throwError, }); } @@ -263,11 +266,12 @@ export abstract class OCPPRequestService { messagePayload: JsonType | OCPPError, messageType: MessageType, commandName: RequestCommand | IncomingRequestCommand, - params: RequestParams = { - skipBufferingOnError: false, - triggerMessage: false, - } + params: RequestParams = defaultRequestParams ): Promise { + params = { + ...defaultRequestParams, + ...params, + }; if ( (chargingStation.inUnknownState() === true && commandName === RequestCommand.BOOT_NOTIFICATION) || @@ -478,18 +482,6 @@ export abstract class OCPPRequestService { return messageToSend; } - private handleSendMessageError( - chargingStation: ChargingStation, - commandName: RequestCommand | IncomingRequestCommand, - error: Error, - params: HandleErrorParams = { throwError: false } - ): void { - logger.error(`${chargingStation.logPrefix()} Request command '${commandName}' error:`, error); - if (params?.throwError === true) { - throw error; - } - } - // eslint-disable-next-line @typescript-eslint/no-unused-vars public abstract requestHandler( chargingStation: ChargingStation,