Skip to content

Commit

Permalink
Merge branch 'develop' into intercom.refactor-proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
mihir-4116 authored Mar 12, 2024
2 parents 544d4d4 + e43b83d commit ebbb8e8
Show file tree
Hide file tree
Showing 12 changed files with 3,446 additions and 582 deletions.
8 changes: 6 additions & 2 deletions src/cdk/v2/destinations/algolia/rtWorkflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ bindings:
- path: ../../../../v0/destinations/algolia/config
- name: handleRtTfSingleEventError
path: ../../../../v0/util/index

steps:
- name: validateInput
template: |
Expand All @@ -28,10 +27,14 @@ steps:
$.outputs.transform#idx.error.(
$.handleRtTfSingleEventError(^[idx], .originalError ?? ., {})
)[]
- name: batchSuccessfulEvents
description: Batches the successfulEvents
template: |
let batches = $.chunk($.outputs.successfulEvents, $.MAX_BATCH_SIZE);
const dontBatchTrueEvents = $.outputs.successfulEvents{.metadata.dontBatch}[];
const dontBatchFalseEvents = $.outputs.successfulEvents{!.metadata.dontBatch}[];
let batches = [...$.chunk(dontBatchFalseEvents, $.MAX_BATCH_SIZE), ...$.chunk(dontBatchTrueEvents, 1)];
batches@batch.({
"batchedRequest": {
"body": {
Expand All @@ -56,6 +59,7 @@ steps:
"statusCode": 200,
"destination": batch[0].destination
})[];
- name: finalPayload
template: |
[...$.outputs.failedEvents, ...$.outputs.batchSuccessfulEvents]
84 changes: 84 additions & 0 deletions src/v1/destinations/algolia/networkHandler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/* eslint-disable no-restricted-syntax */
const { TransformerProxyError } = require('../../../v0/util/errorTypes');
const { prepareProxyRequest, proxyRequest } = require('../../../adapters/network');
const { isHttpStatusSuccess, getAuthErrCategoryFromStCode } = require('../../../v0/util/index');

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

const responseHandler = (responseParams) => {
const { destinationResponse, rudderJobMetadata } = responseParams;
const message = `[ALGOLIA Response V1 Handler] - Request Processed Successfully`;
const responseWithIndividualEvents = [];
// response:
// {status: 200, message: 'OK'}
// {response:'[ENOTFOUND] :: DNS lookup failed', status: 400}
// destinationResponse = {
// response: {"status": 422, "message": "EventType must be one of \"click\", \"conversion\" or \"view\""}, status: 422
// }
const { response, status } = destinationResponse;

if (isHttpStatusSuccess(status)) {
for (const mData of rudderJobMetadata) {
const proxyOutputObj = {
statusCode: 200,
metadata: mData,
error: 'success',
};
responseWithIndividualEvents.push(proxyOutputObj);
}

return {
status,
message,
destinationResponse,
response: responseWithIndividualEvents,
};
}

// in case of non 2xx status sending 500 for every event, populate response and update dontBatch to true
const errorMessage = response?.error?.message || response?.message || 'unknown error format';
let serverStatus = 400;
for (const metadata of rudderJobMetadata) {
// handling case if dontBatch is true, and again we got invalid from destination
if (metadata.dontBatch && status === 422) {
responseWithIndividualEvents.push({
statusCode: 400,
metadata,
error: errorMessage,
});
} else {
serverStatus = 500;
metadata.dontBatch = true;
responseWithIndividualEvents.push({
statusCode: 500,
metadata,
error: errorMessage,
});
}
}

// sending back 500 for retry
throw new TransformerProxyError(
`ALGOLIA: Error transformer proxy v1 during ALGOLIA response transformation`,
serverStatus,
{
[tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(status),
},
destinationResponse,
getAuthErrCategoryFromStCode(status),
responseWithIndividualEvents,
);
};

function networkHandler() {
this.prepareProxy = prepareProxyRequest;
this.proxy = proxyRequest;
this.processAxiosResponse = processAxiosResponse;
this.responseHandler = responseHandler;
}

module.exports = { networkHandler };
Loading

0 comments on commit ebbb8e8

Please sign in to comment.