Skip to content

Commit

Permalink
feat: add proxy and partial handling support
Browse files Browse the repository at this point in the history
  • Loading branch information
Gauravudia committed Mar 18, 2024
1 parent 74a2a77 commit f5b5044
Showing 1 changed file with 83 additions and 0 deletions.
83 changes: 83 additions & 0 deletions src/v1/destinations/bloomreach/networkHandler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
const { TransformerProxyError } = require('../../../v0/util/errorTypes');
const { proxyRequest, prepareProxyRequest } = require('../../../adapters/network');
const {
processAxiosResponse,
getDynamicErrorType,
} = require('../../../adapters/utils/networkUtils');
const { isHttpStatusSuccess } = require('../../../v0/util/index');
const tags = require('../../../v0/util/tags');

// {
// "results": [
// {
// "success": true
// },
// {
// "success": false,
// "errors": [
// "At least one id should be specified."
// ]
// }
// ],
// "start_time": 1710750816.8504393,
// "end_time": 1710750816.8518236,
// "success": true
// }
const checkIfEventIsAbortableAndExtractErrorMessage = (element) => {
if (element.success) {
return { isAbortable: false, errorMsg: '' };

Check warning on line 28 in src/v1/destinations/bloomreach/networkHandler.js

View check run for this annotation

Codecov / codecov/patch

src/v1/destinations/bloomreach/networkHandler.js#L28

Added line #L28 was not covered by tests
}

const errorMsg = element.errors.join(', ');
return { isAbortable: true, errorMsg };

Check warning on line 32 in src/v1/destinations/bloomreach/networkHandler.js

View check run for this annotation

Codecov / codecov/patch

src/v1/destinations/bloomreach/networkHandler.js#L31-L32

Added lines #L31 - L32 were not covered by tests
};

const responseHandler = (responseParams) => {
const { destinationResponse, rudderJobMetadata } = responseParams;

Check warning on line 36 in src/v1/destinations/bloomreach/networkHandler.js

View check run for this annotation

Codecov / codecov/patch

src/v1/destinations/bloomreach/networkHandler.js#L36

Added line #L36 was not covered by tests

const message = '[BLOOMREACH Response V1 Handler] - Request Processed Successfully';
const responseWithIndividualEvents = [];
const { response, status } = destinationResponse;

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

View check run for this annotation

Codecov / codecov/patch

src/v1/destinations/bloomreach/networkHandler.js#L38-L40

Added lines #L38 - L40 were not covered by tests

if (isHttpStatusSuccess(status)) {
// check for Partial Event failures and Successes
const { results } = response;
results.forEach((event, idx) => {
const proxyOutput = {

Check warning on line 46 in src/v1/destinations/bloomreach/networkHandler.js

View check run for this annotation

Codecov / codecov/patch

src/v1/destinations/bloomreach/networkHandler.js#L44-L46

Added lines #L44 - L46 were not covered by tests
statusCode: 200,
metadata: rudderJobMetadata[idx],
error: 'success',
};
// update status of partial event if abortable
const { isAbortable, errorMsg } = checkIfEventIsAbortableAndExtractErrorMessage(event);

Check warning on line 52 in src/v1/destinations/bloomreach/networkHandler.js

View check run for this annotation

Codecov / codecov/patch

src/v1/destinations/bloomreach/networkHandler.js#L52

Added line #L52 was not covered by tests
if (isAbortable) {
proxyOutput.statusCode = 400;
proxyOutput.error = errorMsg;

Check warning on line 55 in src/v1/destinations/bloomreach/networkHandler.js

View check run for this annotation

Codecov / codecov/patch

src/v1/destinations/bloomreach/networkHandler.js#L54-L55

Added lines #L54 - L55 were not covered by tests
}
responseWithIndividualEvents.push(proxyOutput);

Check warning on line 57 in src/v1/destinations/bloomreach/networkHandler.js

View check run for this annotation

Codecov / codecov/patch

src/v1/destinations/bloomreach/networkHandler.js#L57

Added line #L57 was not covered by tests
});
return {

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

View check run for this annotation

Codecov / codecov/patch

src/v1/destinations/bloomreach/networkHandler.js#L59

Added line #L59 was not covered by tests
status,
message,
destinationResponse,
response: responseWithIndividualEvents,
};
}
throw new TransformerProxyError(

Check warning on line 66 in src/v1/destinations/bloomreach/networkHandler.js

View check run for this annotation

Codecov / codecov/patch

src/v1/destinations/bloomreach/networkHandler.js#L66

Added line #L66 was not covered by tests
`BLOOMREACH: Error encountered in transformer proxy V1`,
status,
{
[tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(status),
},
destinationResponse,
'',
responseWithIndividualEvents,
);
};
function networkHandler() {
this.proxy = proxyRequest;
this.processAxiosResponse = processAxiosResponse;
this.prepareProxy = prepareProxyRequest;
this.responseHandler = responseHandler;

Check warning on line 81 in src/v1/destinations/bloomreach/networkHandler.js

View check run for this annotation

Codecov / codecov/patch

src/v1/destinations/bloomreach/networkHandler.js#L77-L81

Added lines #L77 - L81 were not covered by tests
}
module.exports = { networkHandler };

0 comments on commit f5b5044

Please sign in to comment.