Skip to content

Commit

Permalink
chore: onboard rakuten proxy on v1
Browse files Browse the repository at this point in the history
  • Loading branch information
anantjain45823 committed Feb 1, 2024
1 parent f5dd832 commit 6facf4a
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 35 deletions.
2 changes: 1 addition & 1 deletion src/v0/destinations/salesforce/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
const {
NetworkError,
InstrumentationError,
ConfigurationError,
} = require('@rudderstack/integrations-lib');
const { TransformerProxyError } = require('../../../v0/util/errorTypes');
const { httpSend } = require('../../../adapters/network');
const {
processAxiosResponse,
getDynamicErrorType,
} = 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) => {
Expand All @@ -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),
},
Expand All @@ -51,9 +47,9 @@ const responseHandler = (destinationResponse) => {

// For access denied for a mid rakuten sends status code 200 with response as <response> <error> Access denied </error> </response>
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),
Expand All @@ -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),
Expand All @@ -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,
{
Expand Down
121 changes: 103 additions & 18 deletions test/integrations/destinations/rakuten/dataDelivery/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -25,23 +26,47 @@ export const data = [
...commonParams,
},
userId: '',
metadata: [
{
jobId: 2,
attemptNum: 0,
userId: '',
sourceId: 'dummySourceId',
destinationId: 'dummyDestId',
workspaceId: 'dummyWorkspaceId',
},
],
},
},
},
output: {
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:
'<!doctype html><html lang="en"><head><title>HTTP Status 400 – Bad Request</title><style type="text/css">h1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} h2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} h3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} body {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} b {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} p {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;} a {color:black;} a.name {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 400 – Bad Request</h1></body></html>',
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',
},
Expand All @@ -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: {
Expand All @@ -64,23 +90,46 @@ export const data = [
...commonParams,
},
userId: '',
metadata: [
{
jobId: 2,
attemptNum: 0,
userId: '',
sourceId: 'dummySourceId',
destinationId: 'dummyDestId',
workspaceId: 'dummyWorkspaceId',
},
],
},
},
},
output: {
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: '<response><error>Access denied</error></response>',
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.',
Expand All @@ -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: {
Expand All @@ -104,23 +154,47 @@ export const data = [
...commonParams,
},
userId: '',
metadata: [
{
jobId: 2,
attemptNum: 0,
userId: '',
sourceId: 'dummySourceId',
destinationId: 'dummyDestId',
workspaceId: 'dummyWorkspaceId',
},
],
},
},
},
output: {
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:
'<response><unique_id>143407391431</unique_id><summary><transactions><good>0</good><bad>3</bad></transactions></summary></response>',
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',
},
Expand All @@ -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: {
Expand All @@ -143,14 +218,24 @@ export const data = [
...commonParams,
},
userId: '',
metadata: [
{
jobId: 2,
attemptNum: 0,
userId: '',
sourceId: 'dummySourceId',
destinationId: 'dummyDestId',
workspaceId: 'dummyWorkspaceId',
},
],
},
},
},
output: {
response: {
status: 200,
destinationResponse:
'<response><unique_id>143407391431</unique_id><summary><transactions><good>3</good><bad>0</bad></transactions></summary></response>',
'<response><unique_id>uniqueId</unique_id><summary><transactions><good>3</good><bad>0</bad></transactions></summary></response>',
message: '[RAKUTEN Response Handler] - Request Processed Successfully',
},
},
Expand Down
8 changes: 6 additions & 2 deletions test/integrations/destinations/rakuten/network.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export const networkCallsData = [
{
description: 'When mid is invalid',
httpReq: {
url: 'https://track.linksynergy.com/ep',
params: {
Expand All @@ -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: {
Expand All @@ -46,6 +48,7 @@ export const networkCallsData = [
},
},
{
description: 'When record along with mid is valid',
httpReq: {
url: 'https://track.linksynergy.com/ep',
params: {
Expand All @@ -65,10 +68,11 @@ export const networkCallsData = [
},
httpRes: {
status: 200,
data: '<response><unique_id>143407391431</unique_id><summary><transactions><good>3</good><bad>0</bad></transactions></summary></response>',
data: '<response><unique_id>uniqueId</unique_id><summary><transactions><good>3</good><bad>0</bad></transactions></summary></response>',
},
},
{
description: 'When records are invalid and mid is valid',
httpReq: {
url: 'https://track.linksynergy.com/ep',
params: {
Expand All @@ -88,7 +92,7 @@ export const networkCallsData = [
},
httpRes: {
status: 200,
data: '<response><unique_id>143407391431</unique_id><summary><transactions><good>0</good><bad>3</bad></transactions></summary></response>',
data: '<response><unique_id>uniqueId</unique_id><summary><transactions><good>0</good><bad>3</bad></transactions></summary></response>',
},
},
];

0 comments on commit 6facf4a

Please sign in to comment.