Skip to content

Commit

Permalink
Merge branch 'feat.transformerProxy-newContract' of https://github.co…
Browse files Browse the repository at this point in the history
…m/rudderlabs/rudder-transformer into feat.transformerProxy-newContract
  • Loading branch information
aashishmalik committed Oct 20, 2023
2 parents c0953f9 + 9b7416f commit 8952559
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 180 deletions.
244 changes: 72 additions & 172 deletions src/v0/destinations/campaign_manager/networkHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const {
processAxiosResponse,
getDynamicErrorType,
} = require('../../../adapters/utils/networkUtils');
const { TransformerProxyError } = require('../../util/errorTypes');
const { RetryableError, NetworkError, AbortedError, TransformerProxyError } = require('../../util/errorTypes');
const tags = require('../../util/tags');

// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand Down Expand Up @@ -91,195 +91,95 @@ function isEventAbortable(element, proxyOutputObj) {

const responseHandler = (destinationResponse) => {
const message = `[CAMPAIGN_MANAGER Response Handler] - Request Processed Successfully`;
const responseWithPartialEvents = []
// destinationResponse = {
// response: {
// hasFailures: true,
// status: [
// {
// conversion: {
// floodlightConfigurationId: "213123123",
// floodlightActivityId: "456543345245",
// timestampMicros: "1668624722555000",
// value: 756234234234,
// quantity: "3",
// ordinal: "1",
// limitAdTracking: false,
// childDirectedTreatment: false,
// gclid: "123",
// nonPersonalizedAd: false,
// treatmentForUnderage: false,
// kind: "dfareporting#conversion",
// },
// kind: "dfareporting#conversionStatus",
// },
// {
// conversion: {
// floodlightConfigurationId: "213123123",
// floodlightActivityId: "456543345245",
// timestampMicros: "1668624722555000",
// value: 756234234234,
// quantity: "3",
// ordinal: "1",
// limitAdTracking: false,
// childDirectedTreatment: false,
// gclid: "123",
// nonPersonalizedAd: false,
// treatmentForUnderage: false,
// kind: "dfareporting#conversion",
// },
// errors: [
// {
// code: "NOT_FOUND",
// message: "Floodlight config id: 213123123 was not found.",
// kind: "dfareporting#conversionError",
// },
// {
// code: "INVALID_ARGUMENT",
// message: "gclid: 123 was not found.",
// kind: "dfareporting#conversionError",
// }
// ],
// kind: "dfareporting#conversionStatus",
// },
// {
// conversion: {
// floodlightConfigurationId: "213123123",
// floodlightActivityId: "456543345245",
// timestampMicros: "1668624722555000",
// value: 756234234234,
// quantity: "3",
// ordinal: "1",
// limitAdTracking: false,
// childDirectedTreatment: false,
// gclid: "123",
// nonPersonalizedAd: false,
// treatmentForUnderage: false,
// kind: "dfareporting#conversion",
// },
// errors: [
// {
// code: "NOT_FOUND",
// message: "Floodlight config id: 213123123 was not found.",
// kind: "dfareporting#conversionError",
// },
// ],
// kind: "dfareporting#conversionStatus",
// },
// ],
// kind: "dfareporting#conversionsBatchInsertResponse",
// },
// status: 200,
// rudderJobMetadata: [{
// jobId: 10,
// attemptNum: 0,
// userId: "",
// sourceId: "24242",
// destinationId: "24242",
// workspaceId: "242424",
// secret: {
// access_token: "atoken",
// refresh_token: "rtoken",
// developer_token: "developer_Token",
// },
// },
// {
// jobId: 11,
// attemptNum: 0,
// userId: "",
// sourceId: "2424",
// destinationId: "24242",
// workspaceId: "24242",
// secret: {
// access_token: "atoken",
// refresh_token: "rtoken",
// developer_token: "developer_Token",
// },
// },
// {
// jobId: 12,
// attemptNum: 0,
// userId: "",
// sourceId: "24242",
// destinationId: "234234",
// workspaceId: "34324",
// secret: {
// access_token: "atoken",
// refresh_token: "rtoken",
// developer_token: "developer_Token",
// },
// }],
// };

const responseWithIndividualEvents = [];
const { response, status, rudderJobMetadata } = destinationResponse;

Check warning on line 95 in src/v0/destinations/campaign_manager/networkHandler.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/campaign_manager/networkHandler.js#L94-L95

Added lines #L94 - L95 were not covered by tests

// destinationResponse = {
// response: {
// error: {
// code: 401,
// message: "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
// errors: [
// {
// message: "Invalid Credentials",
// domain: "global",
// reason: "authError",
// location: "Authorization",
// locationType: "header",
// },
// ],
// status: "UNAUTHENTICATED",
// },
// },
// status: 401,
// };
if (Array.isArray(rudderJobMetadata)) {
if (isHttpStatusSuccess(status)) {
// check for Partial Event failures and Successes
const destPartialStatus = response.status;

Check warning on line 100 in src/v0/destinations/campaign_manager/networkHandler.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/campaign_manager/networkHandler.js#L100

Added line #L100 was not covered by tests

for (const [idx, element] of destPartialStatus.entries()) {
const proxyOutputObj = {

Check warning on line 103 in src/v0/destinations/campaign_manager/networkHandler.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/campaign_manager/networkHandler.js#L102-L103

Added lines #L102 - L103 were not covered by tests
statusCode: 200,
metadata: rudderJobMetadata[idx],
error: "success"
};
// update status of partial event as per retriable or abortable
if (isEventRetryable(element, proxyOutputObj)) {
proxyOutputObj.statusCode = 500;

Check warning on line 110 in src/v0/destinations/campaign_manager/networkHandler.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/campaign_manager/networkHandler.js#L110

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

Check warning on line 112 in src/v0/destinations/campaign_manager/networkHandler.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/campaign_manager/networkHandler.js#L112

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

Check warning on line 114 in src/v0/destinations/campaign_manager/networkHandler.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/campaign_manager/networkHandler.js#L114

Added line #L114 was not covered by tests
}

return {

Check warning on line 117 in src/v0/destinations/campaign_manager/networkHandler.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/campaign_manager/networkHandler.js#L117

Added line #L117 was not covered by tests
status,
message,
destinationResponse,
response: responseWithIndividualEvents
}
}

// in case of failure status, populate response to maintain len(metadata)=len(response)
const errorMessage = response.error?.message || 'unknown error format';
for (const metadata of rudderJobMetadata) {
responseWithIndividualEvents.push({

Check warning on line 128 in src/v0/destinations/campaign_manager/networkHandler.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/campaign_manager/networkHandler.js#L127-L128

Added lines #L127 - L128 were not covered by tests
statusCode: 500,
metadata,
error: errorMessage
});
}

throw new TransformerProxyError(

Check warning on line 135 in src/v0/destinations/campaign_manager/networkHandler.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/campaign_manager/networkHandler.js#L135

Added line #L135 was not covered by tests
`Campaign Manager: Error proxy during CAMPAIGN_MANAGER response transformation`,
500,
{
[tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(status),
},
destinationResponse,
getAuthErrCategoryFromStCode(status),
responseWithIndividualEvents
);
}

const { response, status, rudderJobMetadata } = destinationResponse;
if (isHttpStatusSuccess(status)) {
// check for Partial Event failures and Successes
const destPartialStatus = response.status;

for (const [idx, element] of destPartialStatus.entries()) {
const proxyOutputObj = {
statusCode: 200,
metadata: rudderJobMetadata[idx],
error: "success"
};
// update status of partial event as per retriable or abortable
if (isEventRetryable(element, proxyOutputObj)) {
proxyOutputObj.statusCode = 500;
} else if (isEventAbortable(element, proxyOutputObj)) {
proxyOutputObj.statusCode = 400;
// check for Failures
if (response.hasFailures === true) {
if (checkIfFailuresAreRetryable(response)) {
throw new RetryableError(
`Campaign Manager: Retrying during CAMPAIGN_MANAGER response transformation`,
500,
destinationResponse,
);
} else {
// abort message
throw new AbortedError(
`Campaign Manager: Aborting during CAMPAIGN_MANAGER response transformation`,
400,
destinationResponse,
);
}
responseWithPartialEvents.push(proxyOutputObj);
}

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

// in case of failure status, populate response to maintain len(metadata)=len(response)
const errorMessage = response.error?.message || 'error msg failure';
for (const metadata of rudderJobMetadata) {
responseWithPartialEvents.push({
statusCode: 500,
metadata,
error: errorMessage
});
}

throw new TransformerProxyError(
`Campaign Manager: Error proxy during CAMPAIGN_MANAGER response transformation`,
500,
throw new NetworkError(
`Campaign Manager: ${response.error?.message} during CAMPAIGN_MANAGER response transformation 3`,
status,
{
[tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(status),
},
destinationResponse,
getAuthErrCategoryFromStCode(status),
responseWithPartialEvents
);

};

function networkHandler() {
Expand Down
9 changes: 3 additions & 6 deletions src/v0/util/errorTypes/transformerProxyError.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const tags = require('../tags');
const { BaseError } = require('./base');

const errorTypes = Object.values(tags.ERROR_TYPES);
const metaTypes = Object.values(tags.METADATA);
class TransformerProxyError extends Error {
class TransformerProxyError extends BaseError {
constructor(message, statusCode, statTags, destResponse, authErrorCategory, response) {
const finalStatTags = {

Check warning on line 8 in src/v0/util/errorTypes/transformerProxyError.js

View check run for this annotation

Codecov / codecov/patch

src/v0/util/errorTypes/transformerProxyError.js#L7-L8

Added lines #L7 - L8 were not covered by tests
[tags.TAG_NAMES.ERROR_CATEGORY]: tags.ERROR_CATEGORIES.NETWORK,
Expand All @@ -19,11 +20,7 @@ class TransformerProxyError extends Error {
finalStatTags[tags.TAG_NAMES.META] = statTags[tags.TAG_NAMES.META];

Check warning on line 20 in src/v0/util/errorTypes/transformerProxyError.js

View check run for this annotation

Codecov / codecov/patch

src/v0/util/errorTypes/transformerProxyError.js#L20

Added line #L20 was not covered by tests
}
}
super(message);
this.status = statusCode;
this.statTags = finalStatTags;
this.destinationResponse = destResponse;
this.authErrorCategory = authErrorCategory;
super(message, statusCode, finalStatTags, destResponse, authErrorCategory);
this.response = response;

Check warning on line 24 in src/v0/util/errorTypes/transformerProxyError.js

View check run for this annotation

Codecov / codecov/patch

src/v0/util/errorTypes/transformerProxyError.js#L23-L24

Added lines #L23 - L24 were not covered by tests
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ export const data = [
jobId: 1,
},
],
batched: false,
batched: true,
statusCode: 200,
destination: {
Config: {
Expand Down Expand Up @@ -411,7 +411,7 @@ export const data = [
jobId: 2,
},
],
batched: false,
batched: true,
statusCode: 200,
destination: {
Config: {
Expand Down

0 comments on commit 8952559

Please sign in to comment.