From b56d9ad6f8a6a18d411aac34b36b954ff46723a3 Mon Sep 17 00:00:00 2001 From: Yashasvi Bajpai <33063622+yashasvibajpai@users.noreply.github.com> Date: Thu, 20 Jun 2024 12:25:04 +0530 Subject: [PATCH] chore: update network handler for adobe --- .../adobe_analytics/networkHandler.js | 20 ++- .../adobe_analytics/dataDelivery/data.ts | 3 +- .../adobe_analytics/dataDelivery/other.ts | 134 ++++++++++++++++++ 3 files changed, 155 insertions(+), 2 deletions(-) create mode 100644 test/integrations/destinations/adobe_analytics/dataDelivery/other.ts diff --git a/src/v0/destinations/adobe_analytics/networkHandler.js b/src/v0/destinations/adobe_analytics/networkHandler.js index 8715721f85..80ed1191f3 100644 --- a/src/v0/destinations/adobe_analytics/networkHandler.js +++ b/src/v0/destinations/adobe_analytics/networkHandler.js @@ -1,4 +1,4 @@ -const { InstrumentationError } = require('@rudderstack/integrations-lib'); +const { InstrumentationError, RetryableError } = require('@rudderstack/integrations-lib'); const { proxyRequest, prepareProxyRequest } = require('../../../adapters/network'); const { processAxiosResponse } = require('../../../adapters/utils/networkUtils'); const { DESTINATION } = require('./config'); @@ -20,6 +20,24 @@ const responseHandler = (responseParams) => { const message = `[${DESTINATION}] - Request Processed Successfully`; const { response, status } = destinationResponse; + if (status !== 200) { + // handle non-200 status codes as network errors + switch (status) { + case 500 || 502 || 503 || 505: + throw new RetryableError( + `[${DESTINATION} Response Handler] Request failed for destination ${destType} with status code ${status} due to ${response}`, + ); + case 504: + throw new RetryableError( + `[${DESTINATION} Response Handler] Request failed for destination ${destType} with status code ${status} due to Gateway Timeout`, + ); + // all other scenarios should be retried by default + default: + throw new RetryableError( + `[${DESTINATION} Response Handler] Request failed for destination ${destType} with status code ${status}`, + ); + } + } // Extract values between different tags const responseStatus = extractContent(response, 'status'); diff --git a/test/integrations/destinations/adobe_analytics/dataDelivery/data.ts b/test/integrations/destinations/adobe_analytics/dataDelivery/data.ts index 2535a0639e..c12f7111f8 100644 --- a/test/integrations/destinations/adobe_analytics/dataDelivery/data.ts +++ b/test/integrations/destinations/adobe_analytics/dataDelivery/data.ts @@ -1,4 +1,5 @@ import { testScenariosForV1API } from './business'; +import { otherScenariosV1 } from './other'; const legacyTests = [ { @@ -143,4 +144,4 @@ const legacyTests = [ }, ]; -export const data = [...testScenariosForV1API, ...legacyTests]; +export const data = [...testScenariosForV1API, ...legacyTests, ...otherScenariosV1]; diff --git a/test/integrations/destinations/adobe_analytics/dataDelivery/other.ts b/test/integrations/destinations/adobe_analytics/dataDelivery/other.ts new file mode 100644 index 0000000000..78513d580d --- /dev/null +++ b/test/integrations/destinations/adobe_analytics/dataDelivery/other.ts @@ -0,0 +1,134 @@ +import { ProxyV1TestData } from '../../../testTypes'; +import { generateMetadata, generateProxyV1Payload } from '../../../testUtils'; + +const expectedStatTags = { + errorCategory: 'network', + errorType: 'retryable', + destType: 'ADOBE_ANALYTICS', + module: 'destination', + implementation: 'native', + feature: 'dataDelivery', + destinationId: 'default-destinationId', + workspaceId: 'default-workspaceId', +}; + +export const otherScenariosV1: ProxyV1TestData[] = [ + { + id: 'adobe_v1_other_scenario_1', + name: 'adobe_analytics', + description: + '[Proxy v1 API] :: Scenario for testing Service Unavailable error from destination', + successCriteria: 'Should return 500 status code with error message', + scenario: 'Framework', + feature: 'dataDelivery', + module: 'destination', + version: 'v1', + input: { + request: { + body: generateProxyV1Payload({ + endpoint: 'https://random_test_url/test_for_service_not_available', + }), + method: 'POST', + }, + }, + output: { + response: { + status: 200, + body: { + output: { + response: [ + { + error: + '[ADOBE_ANALYTICS Response Handler] Request failed for destination adobe_analytics with status code 503', + statusCode: 500, + metadata: generateMetadata(1), + }, + ], + statTags: expectedStatTags, + message: + '[ADOBE_ANALYTICS Response Handler] Request failed for destination adobe_analytics with status code 503', + status: 500, + }, + }, + }, + }, + }, + { + id: 'adobe_v1_other_scenario_2', + name: 'adobe_analytics', + description: '[Proxy v1 API] :: Scenario for testing Internal Server error from destination', + successCriteria: 'Should return 500 status code with error message', + scenario: 'Framework', + feature: 'dataDelivery', + module: 'destination', + version: 'v1', + input: { + request: { + body: generateProxyV1Payload({ + endpoint: 'https://random_test_url/test_for_internal_server_error', + }), + method: 'POST', + }, + }, + output: { + response: { + status: 200, + body: { + output: { + response: [ + { + error: + '[ADOBE_ANALYTICS Response Handler] Request failed for destination adobe_analytics with status code 500 due to Internal Server Error', + statusCode: 500, + metadata: generateMetadata(1), + }, + ], + statTags: expectedStatTags, + message: + '[ADOBE_ANALYTICS Response Handler] Request failed for destination adobe_analytics with status code 500 due to Internal Server Error', + status: 500, + }, + }, + }, + }, + }, + { + id: 'adobe_v1_other_scenario_3', + name: 'adobe_analytics', + description: '[Proxy v1 API] :: Scenario for testing Gateway Time Out error from destination', + successCriteria: 'Should return 504 status code with error message', + scenario: 'Framework', + feature: 'dataDelivery', + module: 'destination', + version: 'v1', + input: { + request: { + body: generateProxyV1Payload({ + endpoint: 'https://random_test_url/test_for_gateway_time_out', + }), + method: 'POST', + }, + }, + output: { + response: { + status: 200, + body: { + output: { + response: [ + { + error: + '[ADOBE_ANALYTICS Response Handler] Request failed for destination adobe_analytics with status code 504 due to Gateway Timeout', + statusCode: 500, + metadata: generateMetadata(1), + }, + ], + statTags: expectedStatTags, + message: + '[ADOBE_ANALYTICS Response Handler] Request failed for destination adobe_analytics with status code 504 due to Gateway Timeout', + status: 500, + }, + }, + }, + }, + }, +];