From fe97f9eb41c99186fd7bdb677d151ab49bab3e95 Mon Sep 17 00:00:00 2001 From: Manish Kumar Date: Fri, 13 Dec 2024 08:08:40 +0530 Subject: [PATCH] fix: moving networkHandler to v1 from v0 --- .../destinations/reddit/networkHandler.js | 39 ++++++++++--------- .../reddit/dataDelivery/business.ts | 12 +++++- .../destinations/reddit/dataDelivery/oauth.ts | 10 ++--- 3 files changed, 34 insertions(+), 27 deletions(-) rename src/{v0 => v1}/destinations/reddit/networkHandler.js (77%) diff --git a/src/v0/destinations/reddit/networkHandler.js b/src/v1/destinations/reddit/networkHandler.js similarity index 77% rename from src/v0/destinations/reddit/networkHandler.js rename to src/v1/destinations/reddit/networkHandler.js index f9e4fd4a27..73d9e12082 100644 --- a/src/v0/destinations/reddit/networkHandler.js +++ b/src/v1/destinations/reddit/networkHandler.js @@ -1,32 +1,30 @@ const { RetryableError, TAG_NAMES, NetworkError } = require('@rudderstack/integrations-lib'); const isString = require('lodash/isString'); const { prepareProxyRequest, proxyRequest } = require('../../../adapters/network'); -const { isHttpStatusSuccess } = require('../../util/index'); +const { isHttpStatusSuccess } = require('../../../v0/util/index'); const { REFRESH_TOKEN } = require('../../../adapters/networkhandler/authConstants'); const { processAxiosResponse, getDynamicErrorType, } = require('../../../adapters/utils/networkUtils'); -const { TransformerProxyError } = require('../../util/errorTypes'); -const tags = require('../../util/tags'); +const { TransformerProxyError } = require('../../../v0/util/errorTypes'); const populateResponseWithDontBatch = (rudderJobMetadata, response) => { const errorMessage = JSON.stringify(response); - const responseWithIndividualEvents = []; - - rudderJobMetadata.forEach((metadata) => { - responseWithIndividualEvents.push({ + return rudderJobMetadata.map(metadata => { + // eslint-disable-next-line no-param-reassign + metadata.dontBatch = true; + return { statusCode: 500, - metadata: { ...metadata, dontBatch: true }, + metadata, error: errorMessage, - }); + }; }); - return responseWithIndividualEvents; }; const redditRespHandler = (responseParams) => { - const { destinationResponse, destinationRequest } = responseParams; + const { destinationResponse, rudderJobMetadata } = responseParams; const { status, response } = destinationResponse; // to handle the case when authorization-token is invalid @@ -49,17 +47,14 @@ const redditRespHandler = (responseParams) => { authErrorCategory, ); } - if (Array.isArray(destinationRequest.metadata) && destinationRequest.metadata.length > 1) { + if (status === 400 && Array.isArray(rudderJobMetadata) && rudderJobMetadata.length > 1) { // sending back 500 for retry only when events came in a batch - const responseWithDontBatch = populateResponseWithDontBatch( - destinationRequest.metadata, - response, - ); + const responseWithDontBatch = populateResponseWithDontBatch(rudderJobMetadata, response); throw new TransformerProxyError( `REDDIT: Error transformer proxy during REDDIT response transformation`, 500, { - [tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(500), + [TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(500), }, destinationResponse, '', @@ -77,7 +72,7 @@ const redditRespHandler = (responseParams) => { ); }; const responseHandler = (responseParams) => { - const { destinationResponse } = responseParams; + const { destinationResponse, rudderJobMetadata } = responseParams; const message = `Request Processed Successfully`; const { status } = destinationResponse; if (!isHttpStatusSuccess(status)) { @@ -90,11 +85,17 @@ const responseHandler = (responseParams) => { ? response?.invalid_events[0]?.error_message : null; const destResp = errorMessage || destinationResponse; + const responseWithIndividualEvents = rudderJobMetadata.map((metadata) => ({ + statusCode: 200, + metadata, + error: 'success', + })); // Mostly any error will not have a status of 2xx return { status, message, - destResp, + destinationResponse: destResp, + response: responseWithIndividualEvents, }; }; // eslint-disable-next-line @typescript-eslint/naming-convention diff --git a/test/integrations/destinations/reddit/dataDelivery/business.ts b/test/integrations/destinations/reddit/dataDelivery/business.ts index e22e612e3f..cc2feccffa 100644 --- a/test/integrations/destinations/reddit/dataDelivery/business.ts +++ b/test/integrations/destinations/reddit/dataDelivery/business.ts @@ -138,13 +138,14 @@ export const testScenariosForV0API = [ status: 200, body: { output: { - destResp: { + destinationResponse: { response: { message: 'Successfully processed 1 conversion events.', }, status: 200, }, - message: 'Request Processed Successfully', + message: + '[Generic Response Handler] Request for destination: reddit Processed Successfully', status: 200, }, }, @@ -181,8 +182,15 @@ export const testScenariosForV1API = [ body: { output: { message: 'Request Processed Successfully', + destinationResponse: { + response: { + message: 'Successfully processed 1 conversion events.', + }, + status: 200, + }, response: [ { + error: 'success', metadata: generateMetadata(1), statusCode: 200, }, diff --git a/test/integrations/destinations/reddit/dataDelivery/oauth.ts b/test/integrations/destinations/reddit/dataDelivery/oauth.ts index 8c0d486a7a..e3c5875a06 100644 --- a/test/integrations/destinations/reddit/dataDelivery/oauth.ts +++ b/test/integrations/destinations/reddit/dataDelivery/oauth.ts @@ -84,14 +84,13 @@ export const v0oauthScenarios = [ status: 401, body: { output: { - authErrorCategory: 'REFRESH_TOKEN', destinationResponse: { response: 'Authorization Required', status: 401, }, message: - 'Request failed due to Authorization Required during reddit response transformation', - statTags: expectedStatTags, + '[Generic Response Handler] Request failed for destination reddit with status: 401', + statTags: { ...expectedStatTags, errorType: 'aborted' }, status: 401, }, }, @@ -121,7 +120,6 @@ export const v0oauthScenarios = [ status: 401, body: { output: { - authErrorCategory: 'REFRESH_TOKEN', destinationResponse: { response: { success: false, @@ -134,8 +132,8 @@ export const v0oauthScenarios = [ status: 401, }, message: - 'This server could not verify that you are authorized to access the document you requested. during reddit response transformation', - statTags: expectedStatTags, + '[Generic Response Handler] Request failed for destination reddit with status: 401', + statTags: { ...expectedStatTags, errorType: 'aborted' }, status: 401, }, },