X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2Focpp%2FOCPPRequestService.ts;h=d2122a65ad2f281c7a9de9cd6b9afcbbeeb87a9d;hb=0ed4ca0a1bd55fddf3c219e8cca11ca6d7f33b54;hp=3eb85e3089a232f21b50b5082e644dceec573505;hpb=721f634101285d00d1c695031ed357b090d1a8f3;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ocpp/OCPPRequestService.ts b/src/charging-station/ocpp/OCPPRequestService.ts index 3eb85e30..d2122a65 100644 --- a/src/charging-station/ocpp/OCPPRequestService.ts +++ b/src/charging-station/ocpp/OCPPRequestService.ts @@ -1,16 +1,16 @@ import Ajv, { type JSONSchemaType } from 'ajv'; import ajvFormats from 'ajv-formats'; -import { OCPPConstants, type OCPPResponseService, OCPPServiceUtils } from './internal'; +import { OCPPConstants } from './OCPPConstants'; +import type { OCPPResponseService } from './OCPPResponseService'; +import { OCPPServiceUtils } from './OCPPServiceUtils'; import type { ChargingStation } from '../../charging-station'; import { OCPPError } from '../../exception'; import { PerformanceStatistics } from '../../performance'; import { - type EmptyObject, type ErrorCallback, type ErrorResponse, ErrorType, - type HandleErrorParams, type IncomingRequestCommand, type JsonObject, type JsonType, @@ -23,7 +23,7 @@ import { type ResponseCallback, type ResponseType, } from '../../types'; -import { Constants, Utils, logger } from '../../utils'; +import { Constants, ErrorUtils, Utils, logger } from '../../utils'; const moduleName = 'OCPPRequestService'; @@ -127,7 +127,7 @@ export abstract class OCPPRequestService { commandName ); } catch (error) { - this.handleSendMessageError(chargingStation, commandName, error as Error, { + ErrorUtils.handleSendMessageError(chargingStation, commandName, error as Error, { throwError: true, }); } @@ -149,7 +149,7 @@ export abstract class OCPPRequestService { commandName ); } catch (error) { - this.handleSendMessageError(chargingStation, commandName, error as Error); + ErrorUtils.handleSendMessageError(chargingStation, commandName, error as Error); } } @@ -164,6 +164,10 @@ export abstract class OCPPRequestService { throwError: false, } ): Promise { + params = { + ...{ skipBufferingOnError: false, triggerMessage: false, throwError: false }, + ...params, + }; try { return await this.internalSendMessage( chargingStation, @@ -174,7 +178,7 @@ export abstract class OCPPRequestService { params ); } catch (error) { - this.handleSendMessageError(chargingStation, commandName, error as Error, { + ErrorUtils.handleSendMessageError(chargingStation, commandName, error as Error, { throwError: params.throwError, }); } @@ -263,8 +267,13 @@ export abstract class OCPPRequestService { params: RequestParams = { skipBufferingOnError: false, triggerMessage: false, + throwError: false, } ): Promise { + params = { + ...{ skipBufferingOnError: false, triggerMessage: false, throwError: false }, + ...params, + }; if ( (chargingStation.inUnknownState() === true && commandName === RequestCommand.BOOT_NOTIFICATION) || @@ -475,18 +484,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,