fix: handle not found hashId in UI server
authorJérôme Benoit <jerome.benoit@sap.com>
Thu, 30 Nov 2023 16:51:19 +0000 (17:51 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Thu, 30 Nov 2023 16:51:19 +0000 (17:51 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ui-server/ui-services/AbstractUIService.ts

index a190b60395e216f8c0a46ec6e6ad1ad0597829f5..d7595c26db164589e1cfb807812fab72be7a3c0b 100644 (file)
@@ -162,18 +162,21 @@ export abstract class AbstractUIService {
   ): void {
     if (isNotEmptyArray(payload.hashIds)) {
       payload.hashIds = payload.hashIds
-        ?.filter((hashId) => !isNullOrUndefined(hashId))
         ?.map((hashId) => {
           if (this.uiServer.chargingStations.has(hashId) === true) {
             return hashId;
           }
-          logger.warn(
-            `${this.logPrefix(
-              moduleName,
-              'sendBroadcastChannelRequest',
-            )} Charging station with hashId '${hashId}' not found`,
-          );
-        }) as string[];
+          const msg = `${this.logPrefix(
+            moduleName,
+            'sendBroadcastChannelRequest',
+          )} Charging station with hashId '${hashId}' not found`;
+          if (payload.hashIds?.length === 1) {
+            throw new BaseError(msg);
+          } else {
+            logger.warn(msg);
+          }
+        })
+        ?.filter((hashId) => !isNullOrUndefined(hashId)) as string[];
     }
     const expectedNumberOfResponses = isNotEmptyArray(payload.hashIds)
       ? payload.hashIds!.length