From 6fcac7ae8aeb7c1d9ffabe36cea8a4dbe6fd9784 Mon Sep 17 00:00:00 2001
From: Ujjwal Abhishek <63387036+ujjwal-ab@users.noreply.github.com>
Date: Tue, 26 Sep 2023 12:14:43 +0530
Subject: [PATCH] chore: update fb_error message for invalid type of property
 value (#2656)

fix: fb_error message for invalid type of property value
---
 src/v0/destinations/fb/transform.js       | 13 +++++++------
 test/__tests__/data/fb_output.json        |  6 +++---
 test/__tests__/data/fb_router_output.json |  2 +-
 3 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/src/v0/destinations/fb/transform.js b/src/v0/destinations/fb/transform.js
index a6a8b71e8dc..756c74ba83c 100644
--- a/src/v0/destinations/fb/transform.js
+++ b/src/v0/destinations/fb/transform.js
@@ -161,7 +161,7 @@ function sanityCheckPayloadForTypesAndModifications(updatedEvent) {
   return clonedUpdatedEvent;
 }
 
-function getCorrectedTypedValue(pathToKey, value, originalPath) {
+function getCorrectedTypedValue(pathToKey, value) {
   const type = eventPropToTypeMapping[pathToKey];
   // TODO: we should remove this eslint rule or comeup with a better way
   // eslint-disable-next-line valid-typeof
@@ -169,10 +169,12 @@ function getCorrectedTypedValue(pathToKey, value, originalPath) {
     return value;
   }
 
+  const mappingKey = Object.keys(eventPropsMapping).find(
+    (key) => eventPropsMapping[key] === pathToKey,
+  );
+
   throw new InstrumentationError(
-    `${
-      typeof originalPath === 'object' ? JSON.stringify(originalPath) : originalPath
-    } is not of valid type`,
+    `Value of ${mappingKey} is not of valid type. It should be of type ${type}`,
   );
 }
 
@@ -221,7 +223,6 @@ function processEventTypeGeneric(message, baseEvent, fbEventName) {
             updatedEvent.custom_events[0][fbEventPath][length] = getCorrectedTypedValue(
               fbEventPath,
               intendValue,
-              parentArray[length],
             );
             length += 1;
             count -= 1;
@@ -233,7 +234,7 @@ function processEventTypeGeneric(message, baseEvent, fbEventName) {
           set(
             updatedEvent.custom_events[0],
             fbEventPath,
-            getCorrectedTypedValue(fbEventPath, intendValue, rudderEventPath),
+            getCorrectedTypedValue(fbEventPath, intendValue),
           );
         }
       } else {
diff --git a/test/__tests__/data/fb_output.json b/test/__tests__/data/fb_output.json
index a974fffe7ee..2923e1720ee 100644
--- a/test/__tests__/data/fb_output.json
+++ b/test/__tests__/data/fb_output.json
@@ -3,10 +3,10 @@
     "message": "If properties.revenue is present, properties.currency is required."
   },
   {
-    "message": "{\"product_id\":123} is not of valid type"
+    "message": "Value of properties.products.sub.product_id is not of valid type. It should be of type string"
   },
   {
-    "message": "properties.revenue is not of valid type"
+    "message": "Value of properties.revenue is not of valid type. It should be of type number"
   },
   {
     "body": {
@@ -307,4 +307,4 @@
     "userId": "c82cbdff-e5be-4009-ac78-cdeea09ab4b1",
     "statusCode": 200
   }
-]
\ No newline at end of file
+]
diff --git a/test/__tests__/data/fb_router_output.json b/test/__tests__/data/fb_router_output.json
index 508d83cc606..5dd568cca5c 100644
--- a/test/__tests__/data/fb_router_output.json
+++ b/test/__tests__/data/fb_router_output.json
@@ -35,6 +35,6 @@
     },
     "batched": false,
     "statusCode": 400,
-    "error": "{\"product_id\":123} is not of valid type"
+    "error": "Value of properties.products.sub.product_id is not of valid type. It should be of type string"
   }
 ]