From 2b38e2c6a5d3556112c7bf2d0aff516a46acfeb8 Mon Sep 17 00:00:00 2001 From: Anant Jain <62471433+anantjain45823@users.noreply.github.com> Date: Fri, 15 Sep 2023 12:57:12 +0530 Subject: [PATCH] Revert "fix(INT-339): marketo response handler to handle static list removed and skipped statuses" (#2619) Revert "fix(INT-339): marketo response handler to handle static list removed and skipped statuses (#2606)" This reverts commit e3fed49d2725a6c60409db00cfda2a997da78e71. --- src/v0/destinations/marketo/util.js | 77 ++++++++----------- .../marketo_static_list/proxy_response.json | 34 +------- .../data/marketo_static_list_proxy_input.json | 20 ----- .../marketo_static_list_proxy_output.json | 67 ++++------------ 4 files changed, 52 insertions(+), 146 deletions(-) diff --git a/src/v0/destinations/marketo/util.js b/src/v0/destinations/marketo/util.js index 1da9dc0f7e..ab39aafc15 100644 --- a/src/v0/destinations/marketo/util.js +++ b/src/v0/destinations/marketo/util.js @@ -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', @@ -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'); @@ -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: { @@ -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)}`, diff --git a/test/__mocks__/data/marketo_static_list/proxy_response.json b/test/__mocks__/data/marketo_static_list/proxy_response.json index 2a58d99da2..5c00ced941 100644 --- a/test/__mocks__/data/marketo_static_list/proxy_response.json +++ b/test/__mocks__/data/marketo_static_list/proxy_response.json @@ -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", @@ -87,13 +60,14 @@ "status": "skipped", "reasons": [ { - "code": "1015", - "message": "Lead not in list" + "code": "1004", + "message": "Lead not found" } ] }, + "success": true }, "status": 200 } -} \ No newline at end of file +} diff --git a/test/__tests__/data/marketo_static_list_proxy_input.json b/test/__tests__/data/marketo_static_list_proxy_input.json index 6f84e7416d..85142d68d7 100644 --- a/test/__tests__/data/marketo_static_list_proxy_input.json +++ b/test/__tests__/data/marketo_static_list_proxy_input.json @@ -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", diff --git a/test/__tests__/data/marketo_static_list_proxy_output.json b/test/__tests__/data/marketo_static_list_proxy_output.json index 8ac482b5be..2dfbee0e8e 100644 --- a/test/__tests__/data/marketo_static_list_proxy_output.json +++ b/test/__tests__/data/marketo_static_list_proxy_output.json @@ -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, @@ -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 } } ] \ No newline at end of file