Skip to content

Commit

Permalink
fix: instead of throwing error now ignoring the undefined value in th…
Browse files Browse the repository at this point in the history
…e products array
  • Loading branch information
sandeepdsvs committed Jun 25, 2024
1 parent 057d9a7 commit 512243a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 26 deletions.
9 changes: 3 additions & 6 deletions src/v0/destinations/braze/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,8 @@ function getPurchaseObjs(message, config) {
'Invalid Order Completed event: Properties object is missing in the message',
);
}
const { products, currency: currencyCode } = properties;
const { currency: currencyCode } = properties;
let { products } = properties;
if (!products) {
throw new InstrumentationError(
'Invalid Order Completed event: Products array is missing in the message',
Expand All @@ -581,6 +582,7 @@ function getPurchaseObjs(message, config) {
throw new InstrumentationError('Invalid Order Completed event: Products is not an array');
}

products = products.filter((product) => isDefinedAndNotNull(product));
if (products.length === 0) {
throw new InstrumentationError('Invalid Order Completed event: Products array is empty');
}
Expand All @@ -592,11 +594,6 @@ function getPurchaseObjs(message, config) {
}

products.forEach((product) => {
if (!isDefinedAndNotNull(product)) {
throw new InstrumentationError(
`Invalid product array at index: ${products.indexOf(product)}. product: ${product}`,
);
}
const productId = product.product_id || product.sku;
const { price, quantity, currency: prodCurrencyCode } = product;
if (!isDefinedAndNotNull(productId)) {
Expand Down
24 changes: 4 additions & 20 deletions test/integrations/destinations/braze/processor/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4212,7 +4212,8 @@ export const data = [
body: [
{
statusCode: 400,
error: 'Invalid product array at index: 0. product: null',
error:
'Invalid Order Completed event: Message properties and product at index: 0 is missing currency',
statTags: {
errorCategory: 'dataValidation',
errorType: 'instrumentation',
Expand Down Expand Up @@ -4276,24 +4277,7 @@ export const data = [
},
messageId: '24ecc509-ce3e-473c-8483-ba1ea2c195cb',
properties: {
products: [
undefined,
{
sku: '45790-32',
url: 'https://www.example.com/product/path',
key1: {
key11: 'value1',
key22: 'value2',
},
name: 'Monopoly: 3rd Edition',
price: 19,
category: 'Games',
quantity: 1,
image_url: 'https:///www.example.com/product/path.jpg',
currency78: 'USD',
product_id: '507f1f77bcf86cd799439011',
},
],
products: [undefined],
},
anonymousId: 'c6ff1462-b692-43d6-8f6a-659efedc99ea',
integrations: {
Expand Down Expand Up @@ -4327,7 +4311,7 @@ export const data = [
body: [
{
statusCode: 400,
error: 'Invalid product array at index: 0. product: null',
error: 'Invalid Order Completed event: Products array is empty',
statTags: {
errorCategory: 'dataValidation',
errorType: 'instrumentation',
Expand Down

0 comments on commit 512243a

Please sign in to comment.