Skip to content

Commit

Permalink
Revert "fix(INT-339): marketo response handler to handle static list …
Browse files Browse the repository at this point in the history
…removed and skipped statuses" (#2619)

Revert "fix(INT-339): marketo response handler to handle static list removed and skipped statuses (#2606)"

This reverts commit e3fed49.
  • Loading branch information
anantjain45823 authored Sep 15, 2023
1 parent dfd6117 commit 2b38e2c
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 146 deletions.
77 changes: 33 additions & 44 deletions src/v0/destinations/marketo/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ const tags = require('../../util/tags');
* https://developers.marketo.com/rest-api/error-codes/
*/

const ERROR_CODE_TO_PASS = ['1015'];

const MARKETO_RETRYABLE_CODES = ['601', '602', '604', '611'];
const MARKETO_ABORTABLE_CODES = [
'600',
Expand All @@ -36,28 +34,29 @@ const MARKETO_ABORTABLE_CODES = [
];
const MARKETO_THROTTLED_CODES = ['502', '606', '607', '608', '615'];

// Keeping here for reference const RECORD_LEVEL_ABORTBALE_ERRORS = [
// '1001',
// '1002',
// '1003',
// '1004',
// '1005',
// '1006',
// '1007',
// '1008',
// '1011',
// '1013',
// '1014',
// '1016',
// '1017',
// '1018',
// '1021',
// '1026',
// '1027',
// '1028',
// '1036',
// '1049',
// ];
const RECORD_LEVEL_ABORTBALE_ERRORS = [
'1001',
'1002',
'1003',
'1004',
'1005',
'1006',
'1007',
'1008',
'1011',
'1013',
'1014',
'1015',
'1016',
'1017',
'1018',
'1021',
'1026',
'1027',
'1028',
'1036',
'1049',
];

const { DESTINATION } = require('./config');
const logger = require('../../../logger');
Expand Down Expand Up @@ -87,7 +86,7 @@ const marketoApplicationErrorHandler = (marketoResponse, sourceMessage, destinat
};
/**
* this function checks the status of individual responses and throws error if any
* response status does not match the expected status
* response ststus does not match the expected status
* doc1: https://developers.marketo.com/rest-api/lead-database/custom-objects/#create_and_update
* doc2: https://developers.marketo.com/rest-api/lead-database/#create_and_update
* Structure of marketoResponse: {
Expand Down Expand Up @@ -123,27 +122,17 @@ const marketoApplicationErrorHandler = (marketoResponse, sourceMessage, destinat
const nestedResponseHandler = (marketoResponse, sourceMessage) => {
const checkStatus = (res) => {
const { status } = res;
const allowedStatus = ['updated', 'added', 'removed', 'created'];
if (
status &&
!allowedStatus.includes(status)
// we need to check the case where the id are not in list
) {
if (status && status !== 'updated' && status !== 'created' && status !== 'added') {
const { reasons } = res;
let statusCode = 400;
if (reasons) {
const errorCodesFromDest = reasons.map((reason) => reason.code);
const filteredErrorCode = errorCodesFromDest.find(
(errorCode) => !ERROR_CODE_TO_PASS.includes(errorCode),
);
if (!filteredErrorCode) {
return;
}
if (MARKETO_THROTTLED_CODES.includes(filteredErrorCode.code)) {
statusCode = 429;
} else if (MARKETO_RETRYABLE_CODES.includes(filteredErrorCode.code)) {
statusCode = 500;
}
if (reasons && RECORD_LEVEL_ABORTBALE_ERRORS.includes(reasons[0].code)) {
statusCode = 400;
} else if (reasons && MARKETO_ABORTABLE_CODES.includes(reasons[0].code)) {
statusCode = 400;
} else if (reasons && MARKETO_THROTTLED_CODES.includes(reasons[0].code)) {
statusCode = 429;
} else if (reasons && MARKETO_RETRYABLE_CODES.includes(reasons[0].code)) {
statusCode = 500;
}
throw new InstrumentationError(
`Request failed during: ${sourceMessage}, error: ${JSON.stringify(reasons)}`,
Expand Down
34 changes: 4 additions & 30 deletions test/__mocks__/data/marketo_static_list/proxy_response.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,4 @@
{
"https://marketo_acct_id_success.mktorest.com/rest/v1/lists/1234/leads.json?id=110&id=111&id=112": {
"data": {
"requestId": "b6d1#18a8d2c10e7",
"result": [
{
"id": 110,
"status": "skipped",
"reasons": [
{
"code": "1015",
"message": "Lead not in list"
}
]
},
{
"id": 111,
"status": "removed"
},
{
"id": 112,
"status": "removed"
}
],
"success": true
},
"status": 200
},
"https://marketo_acct_id_success.mktorest.com/rest/v1/lists/1234/leads.json?id=1&id=2&id=3": {
"data": {
"requestId": "68d8#1846058ee27",
Expand Down Expand Up @@ -87,13 +60,14 @@
"status": "skipped",
"reasons": [
{
"code": "1015",
"message": "Lead not in list"
"code": "1004",
"message": "Lead not found"
}
]
},

"success": true
},
"status": 200
}
}
}
20 changes: 0 additions & 20 deletions test/__tests__/data/marketo_static_list_proxy_input.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,4 @@
[
{
"type": "REST",
"endpoint": "https://marketo_acct_id_success.mktorest.com/rest/v1/lists/1234/leads.json?id=110&id=111&id=112",
"method": "POST",
"userId": "",
"headers": {
"Authorization": "Bearer Incorrect_token",
"Content-Type": "application/json"
},
"body": {
"FORM": {},
"JSON": {},
"JSON_ARRAY": {},
"XML": {}
},
"files": {},
"params": {
"destination": "marketo_static_list"
}
},
{
"type": "REST",
"endpoint": "https://marketo_acct_id_success.mktorest.com/rest/v1/lists/1234/leads.json?id=1&id=2&id=3",
Expand Down
67 changes: 15 additions & 52 deletions test/__tests__/data/marketo_static_list_proxy_output.json
Original file line number Diff line number Diff line change
@@ -1,37 +1,4 @@
[
{
"output": {
"message": "Request Processed Successfully",
"destinationResponse": {
"response": {
"requestId": "b6d1#18a8d2c10e7",
"result": [
{
"id": 110,
"status": "skipped",
"reasons": [
{
"code": "1015",
"message": "Lead not in list"
}
]
},
{
"id": 111,
"status": "removed"
},
{
"id": 112,
"status": "removed"
}
],
"success": true
},
"status": 200
},
"status": 200
}
},
{
"output": {
"status": 500,
Expand Down Expand Up @@ -105,25 +72,21 @@
},
{
"output": {
"status": 200,
"message": "Request Processed Successfully",
"destinationResponse": {
"response": {
"requestId": "12d3c#1846057dce2",
"result": {
"id": 5,
"status": "skipped",
"reasons": [
{
"code": "1015",
"message": "Lead not in list"
}
]
},
"success": true
},
"status": 200
}
"destinationResponse": "",
"message": "Request failed during: during Marketo Static List Response Handling, error: [{\"code\":\"1004\",\"message\":\"Lead not found\"}]",
"statTags": {
"destType": "MARKETO_STATIC_LIST",
"errorCategory": "dataValidation",
"destinationId": "Non-determininable",
"workspaceId": "Non-determininable",
"errorType": "instrumentation",
"feature": "dataDelivery",
"implementation": "native",
"destinationId": "Non-determininable",
"workspaceId": "Non-determininable",
"module": "destination"
},
"status": 400
}
}
]

0 comments on commit 2b38e2c

Please sign in to comment.