Skip to content

Commit

Permalink
chore: update network handler for adobe
Browse files Browse the repository at this point in the history
  • Loading branch information
yashasvibajpai committed Jun 20, 2024
1 parent dc8eae2 commit b56d9ad
Show file tree
Hide file tree
Showing 3 changed files with 155 additions and 2 deletions.
20 changes: 19 additions & 1 deletion src/v0/destinations/adobe_analytics/networkHandler.js
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -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');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { testScenariosForV1API } from './business';
import { otherScenariosV1 } from './other';

const legacyTests = [
{
Expand Down Expand Up @@ -143,4 +144,4 @@ const legacyTests = [
},
];

export const data = [...testScenariosForV1API, ...legacyTests];
export const data = [...testScenariosForV1API, ...legacyTests, ...otherScenariosV1];
134 changes: 134 additions & 0 deletions test/integrations/destinations/adobe_analytics/dataDelivery/other.ts
Original file line number Diff line number Diff line change
@@ -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,
},
},
},
},
},
];

0 comments on commit b56d9ad

Please sign in to comment.