diff --git a/src/v0/destinations/google_adwords_remarketing_lists/networkHandler.js b/src/v0/destinations/google_adwords_remarketing_lists/networkHandler.js index 979f263fcc..563e8b80a6 100644 --- a/src/v0/destinations/google_adwords_remarketing_lists/networkHandler.js +++ b/src/v0/destinations/google_adwords_remarketing_lists/networkHandler.js @@ -99,20 +99,34 @@ const gaAudienceProxyRequest = async (request) => { // step1: offlineUserDataJobs creation const firstResponse = await createJob(endpoint, customerId, listId, headers, method); - if (!firstResponse.success && !isHttpStatusSuccess(firstResponse?.response?.response?.status)) { + if (!firstResponse.success && !isHttpStatusSuccess(firstResponse?.response?.status)) { return firstResponse; } + if (isHttpStatusSuccess(firstResponse?.response?.status)) { + const { partialFailureError } = firstResponse.response.data; + if (partialFailureError && partialFailureError.code !== 0) { + return firstResponse; + } + } + // step2: putting users into the job let jobId; if (firstResponse?.response?.data?.resourceName) // eslint-disable-next-line prefer-destructuring jobId = firstResponse.response.data.resourceName.split('/')[3]; const secondResponse = await addUserToJob(endpoint, headers, method, jobId, body); - if (!secondResponse.success && !isHttpStatusSuccess(secondResponse?.response?.response?.status)) { + if (!secondResponse.success && !isHttpStatusSuccess(secondResponse?.response?.status)) { return secondResponse; } + if (isHttpStatusSuccess(secondResponse?.response?.status)) { + const { partialFailureError } = secondResponse.response.data; + if (partialFailureError && partialFailureError.code !== 0) { + return secondResponse; + } + } + // step3: running the job const thirdResponse = await runTheJob(endpoint, headers, method, jobId); return thirdResponse; @@ -136,8 +150,25 @@ const gaAudienceRespHandler = (destResponse, stageMsg) => { const responseHandler = (destinationResponse) => { const message = `Request Processed Successfully`; - const { status } = destinationResponse; + const { status, response } = destinationResponse; if (isHttpStatusSuccess(status)) { + // for google ads offline conversions the partialFailureError returns with status 200 + const { partialFailureError } = response; + // non-zero code signifies partialFailure + // Ref - https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto + if (partialFailureError && partialFailureError.code !== 0) { + throw new NetworkError( + `[Google Ads Re-marketing Lists]:: partialFailureError - ${JSON.stringify( + partialFailureError, + )}`, + 400, + { + [tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(400), + }, + partialFailureError, + ); + } + // Mostly any error will not have a status of 2xx return { status, diff --git a/test/__mocks__/data/google_adwords_remarketing_lists/proxy_response.json b/test/__mocks__/data/google_adwords_remarketing_lists/proxy_response.json index 246ba7f9fb..5d3ac9496b 100644 --- a/test/__mocks__/data/google_adwords_remarketing_lists/proxy_response.json +++ b/test/__mocks__/data/google_adwords_remarketing_lists/proxy_response.json @@ -6,7 +6,8 @@ } }, "https://googleads.googleapis.com/v14/customers/7693729833/offlineUserDataJobs/18025019461:addOperations": { - "status": 200 + "status": 200, + "data": {} }, "https://googleads.googleapis.com/v14/customers/7693729833/offlineUserDataJobs/18025019461:run": { "status": 200