Skip to content

Commit

Permalink
fix(garl): partial failure handling (#2666)
Browse files Browse the repository at this point in the history
* fix(garl): partial failure handling

* chore: code review changes

* chore: es-lint fix
  • Loading branch information
mihir-4116 authored Oct 4, 2023
1 parent 0ecd031 commit d4cac26
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d4cac26

Please sign in to comment.