X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2Focpp%2FOCPPRequestService.ts;h=f8b6b227a90b3936e3a167d9f22f91ef21138fd5;hb=a65242f09a7a267c37f9bee0dd4fcd33eddbaf70;hp=704838e960c0638eeef967f3480a303bca78f9c3;hpb=b3ec7bc1553759e915e590df6a91f0849f03514d;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ocpp/OCPPRequestService.ts b/src/charging-station/ocpp/OCPPRequestService.ts index 704838e9..f8b6b227 100644 --- a/src/charging-station/ocpp/OCPPRequestService.ts +++ b/src/charging-station/ocpp/OCPPRequestService.ts @@ -6,13 +6,13 @@ import { RequestParams, ResponseType, } from '../../types/ocpp/Requests'; +import { JsonObject, JsonType } from '../../types/JsonType'; import type ChargingStation from '../ChargingStation'; import Constants from '../../utils/Constants'; import { EmptyObject } from '../../types/EmptyObject'; import { ErrorType } from '../../types/ocpp/ErrorType'; import { HandleErrorParams } from '../../types/Error'; -import { JsonType } from '../../types/JsonType'; import { MessageType } from '../../types/ocpp/MessageType'; import OCPPError from '../../exception/OCPPError'; import type OCPPResponseService from './OCPPResponseService'; @@ -36,7 +36,7 @@ export default abstract class OCPPRequestService { this.chargingStation = chargingStation; this.ocppResponseService = ocppResponseService; this.requestHandler.bind(this); - this.sendResult.bind(this); + this.sendResponse.bind(this); this.sendError.bind(this); } @@ -54,13 +54,13 @@ export default abstract class OCPPRequestService { return OCPPRequestService.instances.get(chargingStation.hashId) as T; } - public async sendResult( + public async sendResponse( messageId: string, messagePayload: JsonType, commandName: IncomingRequestCommand ): Promise { try { - // Send result message + // Send response message return await this.internalSendMessage( messageId, messagePayload, @@ -142,7 +142,7 @@ export default abstract class OCPPRequestService { messageType, commandName, responseCallback, - rejectCallback + errorCallback ); if (this.chargingStation.getEnableStatistics()) { this.chargingStation.performanceStatistics.addRequestStatistic( @@ -169,21 +169,21 @@ export default abstract class OCPPRequestService { ErrorType.GENERIC_ERROR, `WebSocket closed for buffered message id '${messageId}' with content '${messageToSend}'`, commandName, - (messagePayload?.details as JsonType) ?? {} + (messagePayload as JsonObject)?.details ?? {} ); if (messageType === MessageType.CALL_MESSAGE) { // Reject it but keep the request in the cache return reject(ocppError); } - return rejectCallback(ocppError, false); + return errorCallback(ocppError, false); } else { // Reject it - return rejectCallback( + return errorCallback( new OCPPError( ErrorType.GENERIC_ERROR, `WebSocket closed for non buffered message id '${messageId}' with content '${messageToSend}'`, commandName, - (messagePayload?.details as JsonType) ?? {} + (messagePayload as JsonObject)?.details ?? {} ), false ); @@ -231,7 +231,7 @@ export default abstract class OCPPRequestService { * @param error * @param requestStatistic */ - function rejectCallback(error: OCPPError, requestStatistic = true): void { + function errorCallback(error: OCPPError, requestStatistic = true): void { if (requestStatistic && self.chargingStation.getEnableStatistics()) { self.chargingStation.performanceStatistics.addRequestStatistic( commandName, @@ -253,7 +253,7 @@ export default abstract class OCPPRequestService { ErrorType.GENERIC_ERROR, `Timeout for message id '${messageId}'`, commandName, - (messagePayload?.details as JsonType) ?? {} + (messagePayload as JsonObject)?.details ?? {} ), () => { messageType === MessageType.CALL_MESSAGE && @@ -274,7 +274,7 @@ export default abstract class OCPPRequestService { messageType: MessageType, commandName?: RequestCommand | IncomingRequestCommand, responseCallback?: (payload: JsonType, requestPayload: JsonType) => Promise, - rejectCallback?: (error: OCPPError, requestStatistic?: boolean) => void + errorCallback?: (error: OCPPError, requestStatistic?: boolean) => void ): string { let messageToSend: string; // Type of message @@ -284,7 +284,7 @@ export default abstract class OCPPRequestService { // Build request this.chargingStation.requests.set(messageId, [ responseCallback, - rejectCallback, + errorCallback, commandName, messagePayload as JsonType, ]);