X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2Focpp%2FOCPPRequestService.ts;h=d2122a65ad2f281c7a9de9cd6b9afcbbeeb87a9d;hb=0ed4ca0a1bd55fddf3c219e8cca11ca6d7f33b54;hp=cc89ab80e75123906b5a54e1a9205bafe59bbc59;hpb=31f59c6d2def2ab2b53240c1d3d35333ac00933b;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ocpp/OCPPRequestService.ts b/src/charging-station/ocpp/OCPPRequestService.ts index cc89ab80..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 { 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,15 +267,20 @@ export abstract class OCPPRequestService { params: RequestParams = { skipBufferingOnError: false, triggerMessage: false, + throwError: false, } ): Promise { + params = { + ...{ skipBufferingOnError: false, triggerMessage: false, throwError: false }, + ...params, + }; if ( - (chargingStation.isInUnknownState() === true && + (chargingStation.inUnknownState() === true && commandName === RequestCommand.BOOT_NOTIFICATION) || (chargingStation.getOcppStrictCompliance() === false && - chargingStation.isInUnknownState() === true) || - chargingStation.isInAcceptedState() === true || - (chargingStation.isInPendingState() === true && + chargingStation.inUnknownState() === true) || + chargingStation.inAcceptedState() === true || + (chargingStation.inPendingState() === true && (params.triggerMessage === true || messageType === MessageType.CALL_RESULT_MESSAGE)) ) { // eslint-disable-next-line @typescript-eslint/no-this-alias @@ -402,7 +411,7 @@ export abstract class OCPPRequestService { return resolve(messagePayload); } }), - Constants.OCPP_WEBSOCKET_TIMEOUT, + OCPPConstants.OCPP_WEBSOCKET_TIMEOUT, new OCPPError( ErrorType.GENERIC_ERROR, `Timeout for message id '${messageId}'`, @@ -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,