diff --git a/src/v1/destinations/bloomreach/networkHandler.js b/src/v1/destinations/bloomreach/networkHandler.js index a3c17a167b..b9c70a80d1 100644 --- a/src/v1/destinations/bloomreach/networkHandler.js +++ b/src/v1/destinations/bloomreach/networkHandler.js @@ -23,12 +23,33 @@ const tags = require('../../../v0/util/tags'); // "end_time": 1710750816.8518236, // "success": true // } +// Catalog response => +// [ +// { +// "errors": { +// "properties": [ +// "Fields [field1, field2] are not properly defined." +// ] +// }, +// "queued": false, +// "success": false +// }, +// { +// "success" : "True", +// "queued" : "True", +// }, +// ] const checkIfEventIsAbortableAndExtractErrorMessage = (element) => { if (element.success) { return { isAbortable: false, errorMsg: '' }; } - const errorMsg = element.errors.join(', '); + const errorMsg = Array.isArray(element.errors) + ? element.errors.join(', ') + : Object.values(element.errors || {}) + .flat() + .join(', '); + return { isAbortable: true, errorMsg }; }; @@ -41,7 +62,11 @@ const responseHandler = (responseParams) => { if (isHttpStatusSuccess(status)) { // check for Partial Event failures and Successes - const { results } = response; + let { results } = response; + // in case of catalog response + if (Array.isArray(response)) { + results = response; + } results.forEach((event, idx) => { const proxyOutput = { statusCode: 200, diff --git a/test/integrations/destinations/bloomreach/dataDelivery/business.ts b/test/integrations/destinations/bloomreach/dataDelivery/business.ts index 9e71b7a2fd..ae3effaf66 100644 --- a/test/integrations/destinations/bloomreach/dataDelivery/business.ts +++ b/test/integrations/destinations/bloomreach/dataDelivery/business.ts @@ -1,6 +1,6 @@ import { ProxyV1TestData } from '../../../testTypes'; import { generateProxyV1Payload, generateMetadata } from '../../../testUtils'; -import { destType, headers, properties, endpoint } from '../common'; +import { destType, headers, properties, endpoint, updateEndpoint } from '../common'; const customerProperties = { email: 'test@example.com', @@ -192,4 +192,69 @@ export const businessProxyV1: ProxyV1TestData[] = [ }, }, }, + { + id: 'bloomreach_v1_business_scenario_3', + name: destType, + description: + '[Proxy v1 API] :: Test for a valid rETL request - where the destination responds with 200 with error', + successCriteria: 'Should return 400 with error message', + scenario: 'Business', + feature: 'dataDelivery', + module: 'destination', + version: 'v1', + input: { + request: { + body: generateProxyV1Payload( + { + headers, + params: {}, + JSON: {}, + JSON_ARRAY: { + batch: [ + { + item_id: 'test-item-id-faulty', + properties: { + unprinted1: '1', + }, + }, + ], + }, + endpoint: updateEndpoint, + }, + [generateMetadata(3)], + ), + method: 'POST', + }, + }, + output: { + response: { + status: 200, + body: { + output: { + status: 200, + message: '[BLOOMREACH Response V1 Handler] - Request Processed Successfully', + destinationResponse: { + response: [ + { + success: false, + queued: false, + errors: { + properties: ['Fields [unprinted1] are not properly defined.'], + }, + }, + ], + status: 200, + }, + response: [ + { + statusCode: 400, + metadata: generateMetadata(3), + error: 'Fields [unprinted1] are not properly defined.', + }, + ], + }, + }, + }, + }, + }, ]; diff --git a/test/integrations/destinations/bloomreach/network.ts b/test/integrations/destinations/bloomreach/network.ts index b20ff881b8..9fc4743928 100644 --- a/test/integrations/destinations/bloomreach/network.ts +++ b/test/integrations/destinations/bloomreach/network.ts @@ -1,4 +1,4 @@ -import { destType, headers, properties, endpoint } from './common'; +import { destType, headers, properties, endpoint, updateEndpoint } from './common'; export const networkCallsData = [ { @@ -121,4 +121,33 @@ export const networkCallsData = [ statusText: 'Ok', }, }, + { + httpReq: { + url: updateEndpoint, + data: [ + { + item_id: 'test-item-id-faulty', + properties: { + unprinted1: '1', + }, + }, + ], + params: { destination: destType }, + headers, + method: 'POST', + }, + httpRes: { + data: [ + { + success: false, + queued: false, + errors: { + properties: ['Fields [unprinted1] are not properly defined.'], + }, + }, + ], + status: 200, + statusText: 'Ok', + }, + }, ];