From: Jérôme Benoit Date: Tue, 20 Sep 2022 16:04:03 +0000 (+0200) Subject: Use a switch case control flow at incoming OCPP messages handling error X-Git-Tag: v1.1.74~27 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=13701f693c8fc29c1575aa91a48ef9453653709e;p=e-mobility-charging-stations-simulator.git Use a switch case control flow at incoming OCPP messages handling error Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index da71a819..ed876d10 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -1563,25 +1563,25 @@ export default class ChargingStation { error ); } - if (messageType === MessageType.CALL_MESSAGE) { - // Send error - await this.ocppRequestService.sendError( - this, - messageId, - error as OCPPError, - commandName ?? requestCommandName ?? null - ); - } else if ( - [MessageType.CALL_RESULT_MESSAGE, MessageType.CALL_ERROR_MESSAGE].includes(messageType) === - true - ) { - if (errorCallback) { - // Reject the deferred promise in case of error at response handling (rejecting an already fulfilled promise is a no-op) - errorCallback(error as OCPPError, false); - } else { - // Remove the request from the cache in case of error at response handling - this.requests.delete(messageId); - } + switch (messageType) { + case MessageType.CALL_MESSAGE: + // Send error + await this.ocppRequestService.sendError( + this, + messageId, + error as OCPPError, + commandName ?? requestCommandName ?? null + ); + break; + case MessageType.CALL_RESULT_MESSAGE: + case MessageType.CALL_ERROR_MESSAGE: + if (errorCallback) { + // Reject the deferred promise in case of error at response handling (rejecting an already fulfilled promise is a no-op) + errorCallback(error as OCPPError, false); + } else { + // Remove the request from the cache in case of error at response handling + this.requests.delete(messageId); + } } } }