Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 44 additions & 33 deletions src/v0/destinations/marketo/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ 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 @@ -34,29 +36,28 @@ const MARKETO_ABORTABLE_CODES = [
];
const MARKETO_THROTTLED_CODES = ['502', '606', '607', '608', '615'];

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',
];
// 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',
// ];
anantjain45823 marked this conversation as resolved.
Show resolved Hide resolved

const { DESTINATION } = require('./config');
const logger = require('../../../logger');
Expand Down Expand Up @@ -86,7 +87,7 @@ const marketoApplicationErrorHandler = (marketoResponse, sourceMessage, destinat
};
/**
* this function checks the status of individual responses and throws error if any
* response ststus does not match the expected status
* response status 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 @@ -122,17 +123,27 @@ const marketoApplicationErrorHandler = (marketoResponse, sourceMessage, destinat
const nestedResponseHandler = (marketoResponse, sourceMessage) => {
const checkStatus = (res) => {
const { status } = res;
if (status && status !== 'updated' && status !== 'created' && status !== 'added') {
const allowedStatus = ['updated', 'added', 'removed', 'created'];
if (
status &&
!allowedStatus.includes(status)
// we need to check the case where the id are not in list
) {
const { reasons } = res;
let statusCode = 400;
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;
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;
}
anantjain45823 marked this conversation as resolved.
Show resolved Hide resolved
}
throw new InstrumentationError(
`Request failed during: ${sourceMessage}, error: ${JSON.stringify(reasons)}`,
Expand Down
34 changes: 30 additions & 4 deletions test/__mocks__/data/marketo_static_list/proxy_response.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,31 @@
{
"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 @@ -60,14 +87,13 @@
"status": "skipped",
"reasons": [
{
"code": "1004",
"message": "Lead not found"
"code": "1015",
"message": "Lead not in list"
}
]
},

"success": true
},
"status": 200
}
}
}
20 changes: 20 additions & 0 deletions test/__tests__/data/marketo_static_list_proxy_input.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
[
{
"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: 52 additions & 15 deletions test/__tests__/data/marketo_static_list_proxy_output.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,37 @@
[
{
"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 @@ -72,21 +105,25 @@
},
{
"output": {
"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
"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
}
}
}
]