From 9ee1f5ca288a6364d40d69c02f723469dd660a8e Mon Sep 17 00:00:00 2001
From: diazjj <jjdiaz@cttc.es>
Date: Thu, 25 Jul 2024 16:31:06 +0200
Subject: [PATCH] Returns empty value if there is no record found by a key.

---
 src/dlt/gateway/dltApp/src/dltGateway.js | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/dlt/gateway/dltApp/src/dltGateway.js b/src/dlt/gateway/dltApp/src/dltGateway.js
index f0ca8120b..7ee723e7c 100644
--- a/src/dlt/gateway/dltApp/src/dltGateway.js
+++ b/src/dlt/gateway/dltApp/src/dltGateway.js
@@ -101,7 +101,10 @@ async function getFromDlt(call, callback) {
 
     // Send the response with the formatted JSON data
     callback(null, { record_id: call.request, data_json: JSON.stringify(result) });
-  } catch (error) {
+  } catch (error) {    if (error.message.includes("data not found for key")) {
+    // Return an empty response when no record is found
+    callback(null, { record_id: call.request, data_json: "{}" });
+  } else {
     // Send failure response with error message
     callback({
       code: grpc.status.UNKNOWN,
-- 
GitLab