Skip to content

Commit

Permalink
fix: fb_error message for invalid type of property value
Browse files Browse the repository at this point in the history
  • Loading branch information
ujjwal-ab committed Sep 26, 2023
1 parent 4f7cbc4 commit 69ab3f9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
13 changes: 7 additions & 6 deletions src/v0/destinations/fb/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,18 +161,20 @@ 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
if (typeof value === type) {
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}`,
);
}

Expand Down Expand Up @@ -221,7 +223,6 @@ function processEventTypeGeneric(message, baseEvent, fbEventName) {
updatedEvent.custom_events[0][fbEventPath][length] = getCorrectedTypedValue(
fbEventPath,
intendValue,
parentArray[length],
);
length += 1;
count -= 1;
Expand All @@ -233,7 +234,7 @@ function processEventTypeGeneric(message, baseEvent, fbEventName) {
set(
updatedEvent.custom_events[0],
fbEventPath,
getCorrectedTypedValue(fbEventPath, intendValue, rudderEventPath),
getCorrectedTypedValue(fbEventPath, intendValue),
);
}
} else {
Expand Down
6 changes: 3 additions & 3 deletions test/__tests__/data/fb_output.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -307,4 +307,4 @@
"userId": "c82cbdff-e5be-4009-ac78-cdeea09ab4b1",
"statusCode": 200
}
]
]
2 changes: 1 addition & 1 deletion test/__tests__/data/fb_router_output.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]

0 comments on commit 69ab3f9

Please sign in to comment.