From 13701f693c8fc29c1575aa91a48ef9453653709e Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 20 Sep 2022 18:04:03 +0200 Subject: [PATCH] Use a switch case control flow at incoming OCPP messages handling error MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/charging-station/ChargingStation.ts | 38 ++++++++++++------------- 1 file changed, 19 insertions(+), 19 deletions(-) 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); + } } } } -- 2.34.1