Skip to content
This repository has been archived by the owner on Jun 12, 2024. It is now read-only.

Commit

Permalink
Factor out OCPP message type to string method
Browse files Browse the repository at this point in the history
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
  • Loading branch information
Jérôme Benoit committed Apr 13, 2022
1 parent 5c370ef commit 9a3b8d9
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/charging-station/ocpp/OCPPRequestService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,20 +154,10 @@ export default abstract class OCPPRequestService {
// FIXME: Handle sending error
this.chargingStation.wsConnection.send(messageToSend);
PerformanceStatistics.endMeasure(commandName, beginId);
let msgTypeStr: string;
switch (messageType) {
case MessageType.CALL_MESSAGE:
msgTypeStr = 'request';
break;
case MessageType.CALL_RESULT_MESSAGE:
msgTypeStr = 'response';
break;
case MessageType.CALL_ERROR_MESSAGE:
msgTypeStr = 'error';
break;
}
logger.debug(
`${this.chargingStation.logPrefix()} >> Command '${commandName}' sent ${msgTypeStr} payload: ${messageToSend}`
`${this.chargingStation.logPrefix()} >> Command '${commandName}' sent ${this.getMessageTypeString(
messageType
)} payload: ${messageToSend}`
);
} else if (!params.skipBufferingOnError) {
// Buffer it
Expand Down Expand Up @@ -317,6 +307,17 @@ export default abstract class OCPPRequestService {
return messageToSend;
}

private getMessageTypeString(messageType: MessageType): string {
switch (messageType) {
case MessageType.CALL_MESSAGE:
return 'request';
case MessageType.CALL_RESULT_MESSAGE:
return 'response';
case MessageType.CALL_ERROR_MESSAGE:
return 'error';
}
}

private handleRequestError(
commandName: RequestCommand | IncomingRequestCommand,
error: Error,
Expand Down

0 comments on commit 9a3b8d9

Please sign in to comment.