Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: addressed comments
Browse files Browse the repository at this point in the history
aashishmalik committed Nov 27, 2023
1 parent 0e06e78 commit abe40e5
Showing 2 changed files with 40 additions and 16 deletions.
25 changes: 25 additions & 0 deletions src/adapters/networkHandlerFactory.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const { getNetworkHandler } = require('./networkHandlerFactory');
const { networkHandler: GenericNetworkHandler } = require('./networkhandler/genericNetworkHandler');

describe(`Network Handler Tests`, () => {
it('Should return v0 networkhandler', () => {
let proxyHandler = getNetworkHandler('campaign_manager', `v0`);
const cmProxy = require(`../v0/destinations/campaign_manager/networkHandler`).networkHandler;
expect(proxyHandler).toEqual(new cmProxy());

proxyHandler = getNetworkHandler('braze', `v0`);
const brazeProxy = require(`../v0/destinations/braze/networkHandler`).networkHandler;
expect(proxyHandler).toEqual(new brazeProxy());
});

it('Should return v1 networkhandler', () => {
let proxyHandler = getNetworkHandler('campaign_manager', `v1`);
const cmProxy = require(`../v1/destinations/campaign_manager/networkHandler`).networkHandler;
expect(proxyHandler).toEqual(new cmProxy());
});

it('Should return genericHandler if v1 proxy and handler is not present for destination', () => {
let proxyHandler = getNetworkHandler('braze', `v1`);
expect(proxyHandler).toEqual(new GenericNetworkHandler());
});
});
31 changes: 15 additions & 16 deletions src/v1/destinations/campaign_manager/networkHandler.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,40 @@
const { NetworkError } = require('@rudderstack/integrations-lib');
/* eslint-disable no-param-reassign */
/* eslint-disable no-restricted-syntax */
const { NetworkError } = require('@rudderstack/integrations-lib');
const { prepareProxyRequest, proxyRequest } = require('../../../adapters/network');
const { isHttpStatusSuccess, getAuthErrCategoryFromStCode } = require('../../../v0/util/index');

const {
processAxiosResponse,
getDynamicErrorType,
} = require('../../../adapters/utils/networkUtils');
// const { TransformerProxyError } = require('../../util/errorTypes');
const tags = require('../../../v0/util/tags');

function isEventRetryable(element, proxyOutputObj) {
let flag = false;
function isEventRetryableAndExtractErrMsg(element, proxyOutputObj) {
let isRetryable = false;
let errorMsg = '';

Check warning on line 15 in src/v1/destinations/campaign_manager/networkHandler.js

Codecov / codecov/patch

src/v1/destinations/campaign_manager/networkHandler.js#L13-L15

Added lines #L13 - L15 were not covered by tests
// success event
if (!element.errors) {
return flag;
return isRetryable;

Check warning on line 18 in src/v1/destinations/campaign_manager/networkHandler.js

Codecov / codecov/patch

src/v1/destinations/campaign_manager/networkHandler.js#L18

Added line #L18 was not covered by tests
}
for (const err of element.errors) {
errorMsg += `${err.message}, `;

Check warning on line 21 in src/v1/destinations/campaign_manager/networkHandler.js

Codecov / codecov/patch

src/v1/destinations/campaign_manager/networkHandler.js#L20-L21

Added lines #L20 - L21 were not covered by tests
if (err.code === 'INTERNAL') {
flag = true;
isRetryable = true;

Check warning on line 23 in src/v1/destinations/campaign_manager/networkHandler.js

Codecov / codecov/patch

src/v1/destinations/campaign_manager/networkHandler.js#L23

Added line #L23 was not covered by tests
}
}
if (errorMsg) {
proxyOutputObj.error = errorMsg;

Check warning on line 27 in src/v1/destinations/campaign_manager/networkHandler.js

Codecov / codecov/patch

src/v1/destinations/campaign_manager/networkHandler.js#L27

Added line #L27 was not covered by tests
}
return flag;
return isRetryable;

Check warning on line 29 in src/v1/destinations/campaign_manager/networkHandler.js

Codecov / codecov/patch

src/v1/destinations/campaign_manager/networkHandler.js#L29

Added line #L29 was not covered by tests
}

function isEventAbortable(element, proxyOutputObj) {
let flag = false;
function isEventAbortableAndExtractErrMsg(element, proxyOutputObj) {
let isAbortable = false;
let errorMsg = '';

Check warning on line 34 in src/v1/destinations/campaign_manager/networkHandler.js

Codecov / codecov/patch

src/v1/destinations/campaign_manager/networkHandler.js#L32-L34

Added lines #L32 - L34 were not covered by tests
// success event
if (!element.errors) {
return flag;
return isAbortable;

Check warning on line 37 in src/v1/destinations/campaign_manager/networkHandler.js

Codecov / codecov/patch

src/v1/destinations/campaign_manager/networkHandler.js#L37

Added line #L37 was not covered by tests
}
for (const err of element.errors) {
errorMsg += `${err.message}, `;

Check warning on line 40 in src/v1/destinations/campaign_manager/networkHandler.js

Codecov / codecov/patch

src/v1/destinations/campaign_manager/networkHandler.js#L39-L40

Added lines #L39 - L40 were not covered by tests
@@ -45,17 +44,17 @@ function isEventAbortable(element, proxyOutputObj) {
err.code === 'INVALID_ARGUMENT' ||
err.code === 'NOT_FOUND'

Check warning on line 45 in src/v1/destinations/campaign_manager/networkHandler.js

Codecov / codecov/patch

src/v1/destinations/campaign_manager/networkHandler.js#L43-L45

Added lines #L43 - L45 were not covered by tests
) {
flag = true;
isAbortable = true;

Check warning on line 47 in src/v1/destinations/campaign_manager/networkHandler.js

Codecov / codecov/patch

src/v1/destinations/campaign_manager/networkHandler.js#L47

Added line #L47 was not covered by tests
}
}
if (errorMsg) {
proxyOutputObj.error = errorMsg;

Check warning on line 51 in src/v1/destinations/campaign_manager/networkHandler.js

Codecov / codecov/patch

src/v1/destinations/campaign_manager/networkHandler.js#L51

Added line #L51 was not covered by tests
}
return flag;
return isAbortable;

Check warning on line 53 in src/v1/destinations/campaign_manager/networkHandler.js

Codecov / codecov/patch

src/v1/destinations/campaign_manager/networkHandler.js#L53

Added line #L53 was not covered by tests
}

const responseHandler = (destinationResponse) => {
const message = `[CAMPAIGN_MANAGER Response Handler] - Request Processed Successfully`;
const message = `[CAMPAIGN_MANAGER Response V1 Handler] - Request Processed Successfully`;
const responseWithIndividualEvents = [];
const { response, status, rudderJobMetadata } = destinationResponse;

Check warning on line 59 in src/v1/destinations/campaign_manager/networkHandler.js

Codecov / codecov/patch

src/v1/destinations/campaign_manager/networkHandler.js#L57-L59

Added lines #L57 - L59 were not covered by tests

@@ -70,9 +69,9 @@ const responseHandler = (destinationResponse) => {
error: 'success',
};
// update status of partial event as per retriable or abortable
if (isEventRetryable(element, proxyOutputObj)) {
if (isEventRetryableAndExtractErrMsg(element, proxyOutputObj)) {
proxyOutputObj.statusCode = 500;

Check warning on line 73 in src/v1/destinations/campaign_manager/networkHandler.js

Codecov / codecov/patch

src/v1/destinations/campaign_manager/networkHandler.js#L73

Added line #L73 was not covered by tests
} else if (isEventAbortable(element, proxyOutputObj)) {
} else if (isEventAbortableAndExtractErrMsg(element, proxyOutputObj)) {
proxyOutputObj.statusCode = 400;

Check warning on line 75 in src/v1/destinations/campaign_manager/networkHandler.js

Codecov / codecov/patch

src/v1/destinations/campaign_manager/networkHandler.js#L75

Added line #L75 was not covered by tests
}
responseWithIndividualEvents.push(proxyOutputObj);

Check warning on line 77 in src/v1/destinations/campaign_manager/networkHandler.js

Codecov / codecov/patch

src/v1/destinations/campaign_manager/networkHandler.js#L77

Added line #L77 was not covered by tests
@@ -97,7 +96,7 @@ const responseHandler = (destinationResponse) => {
}

throw new NetworkError(

Check warning on line 98 in src/v1/destinations/campaign_manager/networkHandler.js

Codecov / codecov/patch

src/v1/destinations/campaign_manager/networkHandler.js#L98

Added line #L98 was not covered by tests
`Campaign Manager: Error proxy during CAMPAIGN_MANAGER response transformation`,
`Campaign Manager: Error proxy v1 during CAMPAIGN_MANAGER response transformation`,
500,
{
[tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(status),

0 comments on commit abe40e5

Please sign in to comment.