Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update network handler for adobe #3487

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even 4xx will be retried ?

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,
},
},
},
},
},
];
Loading