Skip to content

Commit

Permalink
feat: more deduplication
Browse files Browse the repository at this point in the history
  • Loading branch information
shrouti1507 committed Jun 20, 2024
1 parent 71369a9 commit 657f828
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 59 deletions.
96 changes: 43 additions & 53 deletions src/v1/destinations/clicksend/networkHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,70 +33,60 @@ function checkIfEventIsAbortableAndExtractErrorMessage(singleResponse) {
errorMsg: status || campaignStatus || '',
};
}
const handleErrorResponse = (status, response, rudderJobMetadata) => {
const errorMessage = response.replyText || 'unknown error format';
const responseWithIndividualEvents = rudderJobMetadata.map((metadata) => ({
statusCode: status,
metadata,
error: errorMessage,
}));
throw new TransformerProxyError(
`CLICKSEND: Error transformer proxy v1 during CLICKSEND response transformation. ${errorMessage}`,
status,
{
[tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(status),
},
{ response, status },
'',
responseWithIndividualEvents,
);
};

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

if (!isHttpStatusSuccess(status)) {
const errorMessage = response.replyText || 'unknown error format';
responseWithIndividualEvents = rudderJobMetadata.map((metadata) => ({
statusCode: status,
metadata,
error: errorMessage,
}));
throw new TransformerProxyError(
` CLICKSEND: Error transformer proxy v1 during CLICKSEND response transformation. ${errorMessage}`,
status,
{
[tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(status),
},
destinationResponse,
'',
responseWithIndividualEvents,
);
handleErrorResponse(status, response, rudderJobMetadata);
}

if (isHttpStatusSuccess(status)) {
// check for Partial Event failures and Successes
// eslint-disable-next-line @typescript-eslint/naming-convention
const { messages } = response.data;
const finalData = messages || [response.data];
finalData.forEach((singleResponse, idx) => {
const proxyOutput = {
statusCode: 200,
metadata: rudderJobMetadata[idx],
error: 'success',
};
// update status of partial event if abortable
const { isAbortable, errorMsg } = checkIfEventIsAbortableAndExtractErrorMessage(
singleResponse, // array sms send status / entire destination request
);
if (isAbortable) {
proxyOutput.statusCode = 400;
proxyOutput.error = errorMsg;
}
responseWithIndividualEvents.push(proxyOutput);
});
return {
status,
message,
destinationResponse,
response: responseWithIndividualEvents,
const { messages } = response.data;
const finalData = messages || [response.data];
const responseWithIndividualEvents = finalData.map((singleResponse, idx) => {
const proxyOutput = {
statusCode: 200,
metadata: rudderJobMetadata[idx],
error: 'success',
};
}
const { isAbortable, errorMsg } = checkIfEventIsAbortableAndExtractErrorMessage(singleResponse);
if (isAbortable) {
proxyOutput.statusCode = 400;
proxyOutput.error = errorMsg;
}
return proxyOutput;
});

throw new TransformerProxyError(
` CLICKSEND: Error transformer proxy v1 during CLICKSEND response transformation`,
return {
status,
{
[tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(status),
},
message,
destinationResponse,
'',
responseWithIndividualEvents,
);
response: responseWithIndividualEvents,
};
};

module.exports = {
responseHandler,
};

function networkHandler() {
Expand Down
12 changes: 6 additions & 6 deletions test/integrations/destinations/clicksend/dataDelivery/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export const testScenariosForV1API: ProxyV1TestData[] = [
status: 403,
statTags,
message:
' CLICKSEND: Error transformer proxy v1 during CLICKSEND response transformation. unknown error format',
'CLICKSEND: Error transformer proxy v1 during CLICKSEND response transformation. unknown error format',
response: [
{
statusCode: 403,
Expand Down Expand Up @@ -219,7 +219,7 @@ export const testScenariosForV1API: ProxyV1TestData[] = [
status: 404,
statTags,
message:
' CLICKSEND: Error transformer proxy v1 during CLICKSEND response transformation. unknown error format',
'CLICKSEND: Error transformer proxy v1 during CLICKSEND response transformation. unknown error format',
response: [
{
statusCode: 404,
Expand Down Expand Up @@ -262,7 +262,7 @@ export const testScenariosForV1API: ProxyV1TestData[] = [
status: 404,
statTags,
message:
' CLICKSEND: Error transformer proxy v1 during CLICKSEND response transformation. unknown error format',
'CLICKSEND: Error transformer proxy v1 during CLICKSEND response transformation. unknown error format',
response: [
{
statusCode: 404,
Expand Down Expand Up @@ -305,7 +305,7 @@ export const testScenariosForV1API: ProxyV1TestData[] = [
status: 400,
statTags,
message:
' CLICKSEND: Error transformer proxy v1 during CLICKSEND response transformation. unknown error format',
'CLICKSEND: Error transformer proxy v1 during CLICKSEND response transformation. unknown error format',
response: [
{
statusCode: 400,
Expand Down Expand Up @@ -348,7 +348,7 @@ export const testScenariosForV1API: ProxyV1TestData[] = [
status: 404,
statTags,
message:
' CLICKSEND: Error transformer proxy v1 during CLICKSEND response transformation. unknown error format',
'CLICKSEND: Error transformer proxy v1 during CLICKSEND response transformation. unknown error format',
response: [
{
statusCode: 404,
Expand Down Expand Up @@ -481,7 +481,7 @@ export const testScenariosForV1API: ProxyV1TestData[] = [
},
status: 200,
},
message: '[ CLICKSEND Response V1 Handler] - Request Processed Successfully',
message: '[CLICKSEND Response V1 Handler] - Request Processed Successfully',
response: [
{
statusCode: 200,
Expand Down

0 comments on commit 657f828

Please sign in to comment.