diff --git a/src/v0/destinations/salesforce/utils.js b/src/v0/destinations/salesforce/utils.js index 96735ecc17..de62f30dcc 100644 --- a/src/v0/destinations/salesforce/utils.js +++ b/src/v0/destinations/salesforce/utils.js @@ -87,7 +87,7 @@ const salesforceResponseHandler = (destResponse, sourceMessage, authKey, authori } // aborting for all other error codes throw new AbortedError( - `${DESTINATION} Request Failed: "${status}" due to "${ + `${DESTINATION} Request Failed: Anant"${status}" due to "${ errorMessage || JSON.stringify(response) }", (Aborted) ${sourceMessage}`, 400, diff --git a/src/v0/destinations/rakuten/networkHandler.js b/src/v1/destinations/rakuten/networkHandler.js similarity index 88% rename from src/v0/destinations/rakuten/networkHandler.js rename to src/v1/destinations/rakuten/networkHandler.js index 777a8d00ce..f0fdbc7350 100644 --- a/src/v0/destinations/rakuten/networkHandler.js +++ b/src/v1/destinations/rakuten/networkHandler.js @@ -1,8 +1,4 @@ -const { - NetworkError, - InstrumentationError, - ConfigurationError, -} = require('@rudderstack/integrations-lib'); +const { TransformerProxyError } = require('../../../v0/util/errorTypes'); const { httpSend } = require('../../../adapters/network'); const { processAxiosResponse, @@ -10,8 +6,8 @@ const { } = require('../../../adapters/utils/networkUtils'); const DESTINATION = 'RAKUTEN'; -const { TAG_NAMES } = require('../../util/tags'); -const { HTTP_STATUS_CODES } = require('../../util/constant'); +const { TAG_NAMES } = require('../../../v0/util/tags'); +const { HTTP_STATUS_CODES } = require('../../../v0/util/constant'); const prepareProxyRequest = (request) => request; const proxyRequest = async (request, destType) => { @@ -36,9 +32,9 @@ const responseHandler = (destinationResponse) => { const msg = `[${DESTINATION} Response Handler] - Request Processed Successfully`; const { response, status } = destinationResponse; if (status === 400) { - throw new ConfigurationError( + throw new TransformerProxyError( `Request failed with status: ${status} due to invalid Marketing Id`, - status, + 400, { [TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(status), }, @@ -51,9 +47,9 @@ const responseHandler = (destinationResponse) => { // For access denied for a mid rakuten sends status code 200 with response as Access denied if (errors) { - throw new ConfigurationError( + throw new TransformerProxyError( `Request failed with status: ${status} due to ${errors}. Can you try to enable pixel tracking for this mid.`, - status, + 400, { // status would be 200 but since no error type for this status code hence it will take it as aborted [TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(status), @@ -62,9 +58,9 @@ const responseHandler = (destinationResponse) => { ); } if (parseInt(badRecords, 10)) { - throw new InstrumentationError( + throw new TransformerProxyError( `Request failed with status: ${status} with number of bad records ${badRecords}`, - status, + 400, { // status would be 200 but since no error type for this status code hence it will take it as aborted [TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(status), @@ -76,7 +72,7 @@ const responseHandler = (destinationResponse) => { neither we have any sample response but just in case if we recoeve non 2xx status */ if (status !== 200) { - throw new NetworkError( + throw new TransformerProxyError( `Request failed with status: ${status}`, status, { diff --git a/test/integrations/destinations/rakuten/dataDelivery/data.ts b/test/integrations/destinations/rakuten/dataDelivery/data.ts index 621fd030ba..ced8e389f2 100644 --- a/test/integrations/destinations/rakuten/dataDelivery/data.ts +++ b/test/integrations/destinations/rakuten/dataDelivery/data.ts @@ -13,7 +13,8 @@ export const data = [ description: 'Test 0: Failure response from rakuten for invalid mid', feature: 'dataDelivery', module: 'destination', - version: 'v0', + scenario: 'Framework', + version: 'v1', input: { request: { body: { @@ -25,6 +26,16 @@ export const data = [ ...commonParams, }, userId: '', + metadata: [ + { + jobId: 2, + attemptNum: 0, + userId: '', + sourceId: 'dummySourceId', + destinationId: 'dummyDestId', + workspaceId: 'dummyWorkspaceId', + }, + ], }, }, }, @@ -32,16 +43,30 @@ export const data = [ response: { status: 400, statTags: { - errorCategory: 'dataValidation', + errorCategory: 'network', errorType: 'configuration', destType: 'RAKUTEN', module: 'destination', implementation: 'native', feature: 'dataDelivery', - destinationId: 'Non-determininable', - workspaceId: 'Non-determininable', + destinationId: 'dummyDestId', + workspaceId: 'dummyWorkspaceId', + }, + destinationResponse: { + response: + 'HTTP Status 400 – Bad Request

HTTP Status 400 – Bad Request

', + status: 400, + rudderJobMetadata: [ + { + jobId: 2, + attemptNum: 0, + userId: '', + sourceId: 'dummySourceId', + destinationId: 'dummyDestId', + workspaceId: 'dummyWorkspaceId', + }, + ], }, - destinationResponse: '', authErrorCategory: '', message: 'Request failed with status: 400 due to invalid Marketing Id', }, @@ -51,8 +76,9 @@ export const data = [ name: 'rakuten', description: 'Test 1: Failure response from rakuten for access denied for rakuten mid', feature: 'dataDelivery', + scenario: 'Framework', module: 'destination', - version: 'v0', + version: 'v1', input: { request: { body: { @@ -64,6 +90,16 @@ export const data = [ ...commonParams, }, userId: '', + metadata: [ + { + jobId: 2, + attemptNum: 0, + userId: '', + sourceId: 'dummySourceId', + destinationId: 'dummyDestId', + workspaceId: 'dummyWorkspaceId', + }, + ], }, }, }, @@ -71,16 +107,29 @@ export const data = [ response: { status: 400, statTags: { - errorCategory: 'dataValidation', + errorCategory: 'network', errorType: 'configuration', destType: 'RAKUTEN', module: 'destination', implementation: 'native', feature: 'dataDelivery', - destinationId: 'Non-determininable', - workspaceId: 'Non-determininable', + destinationId: 'dummyDestId', + workspaceId: 'dummyWorkspaceId', + }, + destinationResponse: { + response: 'Access denied', + status: 200, + rudderJobMetadata: [ + { + jobId: 2, + attemptNum: 0, + userId: '', + sourceId: 'dummySourceId', + destinationId: 'dummyDestId', + workspaceId: 'dummyWorkspaceId', + }, + ], }, - destinationResponse: '', authErrorCategory: '', message: 'Request failed with status: 200 due to Access denied. Can you try to enable pixel tracking for this mid.', @@ -91,8 +140,9 @@ export const data = [ name: 'rakuten', description: 'Test 2: Failure response from rakuten for bad records>0', feature: 'dataDelivery', + scenario: 'Framework', module: 'destination', - version: 'v0', + version: 'v1', input: { request: { body: { @@ -104,6 +154,16 @@ export const data = [ ...commonParams, }, userId: '', + metadata: [ + { + jobId: 2, + attemptNum: 0, + userId: '', + sourceId: 'dummySourceId', + destinationId: 'dummyDestId', + workspaceId: 'dummyWorkspaceId', + }, + ], }, }, }, @@ -111,16 +171,30 @@ export const data = [ response: { status: 400, statTags: { - errorCategory: 'dataValidation', - errorType: 'instrumentation', + errorCategory: 'network', + errorType: 'aborted', destType: 'RAKUTEN', module: 'destination', implementation: 'native', feature: 'dataDelivery', - destinationId: 'Non-determininable', - workspaceId: 'Non-determininable', + destinationId: 'dummyDestId', + workspaceId: 'dummyWorkspaceId', + }, + destinationResponse: { + response: + '14340739143103', + status: 200, + rudderJobMetadata: [ + { + jobId: 2, + attemptNum: 0, + userId: '', + sourceId: 'dummySourceId', + destinationId: 'dummyDestId', + workspaceId: 'dummyWorkspaceId', + }, + ], }, - destinationResponse: '', authErrorCategory: '', message: 'Request failed with status: 200 with number of bad records 3', }, @@ -130,8 +204,9 @@ export const data = [ name: 'rakuten', description: 'Test 3: Success response from rakuten with good records > 0', feature: 'dataDelivery', + scenario: 'Framework', module: 'destination', - version: 'v0', + version: 'v1', input: { request: { body: { @@ -143,6 +218,16 @@ export const data = [ ...commonParams, }, userId: '', + metadata: [ + { + jobId: 2, + attemptNum: 0, + userId: '', + sourceId: 'dummySourceId', + destinationId: 'dummyDestId', + workspaceId: 'dummyWorkspaceId', + }, + ], }, }, }, @@ -150,7 +235,7 @@ export const data = [ response: { status: 200, destinationResponse: - '14340739143130', + 'uniqueId30', message: '[RAKUTEN Response Handler] - Request Processed Successfully', }, }, diff --git a/test/integrations/destinations/rakuten/network.ts b/test/integrations/destinations/rakuten/network.ts index 2af4217ffd..6f558ba11c 100644 --- a/test/integrations/destinations/rakuten/network.ts +++ b/test/integrations/destinations/rakuten/network.ts @@ -1,5 +1,6 @@ export const networkCallsData = [ { + description: 'When mid is invalid', httpReq: { url: 'https://track.linksynergy.com/ep', params: { @@ -23,6 +24,7 @@ export const networkCallsData = [ }, }, { + description: 'When mid is valid but there is no access', httpReq: { url: 'https://track.linksynergy.com/ep', params: { @@ -46,6 +48,7 @@ export const networkCallsData = [ }, }, { + description: 'When record along with mid is valid', httpReq: { url: 'https://track.linksynergy.com/ep', params: { @@ -65,10 +68,11 @@ export const networkCallsData = [ }, httpRes: { status: 200, - data: '14340739143130', + data: 'uniqueId30', }, }, { + description: 'When records are invalid and mid is valid', httpReq: { url: 'https://track.linksynergy.com/ep', params: { @@ -88,7 +92,7 @@ export const networkCallsData = [ }, httpRes: { status: 200, - data: '14340739143103', + data: 'uniqueId03', }, }, ];