Skip to content

Commit

Permalink
fix: fixing network and default error messages for marketo bulk upload (
Browse files Browse the repository at this point in the history
#3016)

* fix: fixing network error messages

* fix: fixing default error messages
  • Loading branch information
shrouti1507 authored Jan 22, 2024
1 parent 7ab3da0 commit 3741073
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/v0/destinations/marketo_bulk_upload/fileUpload.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ const getImportID = async (input, config, accessToken, csvHeader) => {
stats.counter('marketo_bulk_upload_upload_file_unsuccJobs', unsuccessfulJobs.length);
if (!isHttpStatusSuccess(resp.status)) {
throw new NetworkError(
'Unable to upload file',
hydrateStatusForServer(resp.status, 'During fetching poll status'),
`Unable to upload file due to error : ${resp.response}`,
hydrateStatusForServer(resp.status, 'During uploading file'),
);
}
return handleFileUploadResponse(resp, successfulJobs, unsuccessfulJobs, requestTime, config);
Expand Down
2 changes: 1 addition & 1 deletion src/v0/destinations/marketo_bulk_upload/poll.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const getPollStatus = async (event) => {
state: 'Retryable',
});
throw new NetworkError(
'Could not poll status',
`Could not poll status: due to error ${pollStatus.response}`,
hydrateStatusForServer(pollStatus.status, 'During fetching poll status'),
);
}
Expand Down
23 changes: 17 additions & 6 deletions src/v0/destinations/marketo_bulk_upload/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ const getAccessToken = async (config) =>
// sample response : {response: '[ENOTFOUND] :: DNS lookup failed', status: 400}
if (!isHttpStatusSuccess(accessTokenResponse.status)) {
throw new NetworkError(
'Could not retrieve authorisation token',
`Could not retrieve authorisation token due to error ${accessTokenResponse}`,
hydrateStatusForServer(accessTokenResponse.status, FETCH_ACCESS_TOKEN),
{
[tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(accessTokenResponse.status),
Expand All @@ -172,7 +172,7 @@ const getAccessToken = async (config) =>

// when access token is present
if (accessTokenResponse.response.access_token) {
/* This scenario will handle the case when we get the foloowing response
/* This scenario will handle the case when we get the following response
status: 200
respnse: {"access_token":"<dummy-access-token>","token_type":"bearer","expires_in":0,"scope":"[email protected]"}
wherein "expires_in":0 denotes that we should refresh the accessToken but its not expired yet.
Expand All @@ -185,7 +185,10 @@ const getAccessToken = async (config) =>
}
return accessTokenResponse.response.access_token;
}
throw new AbortedError('Could not retrieve authorisation token', 400);
throw new AbortedError(
`Could not retrieve authorisation token due to error ${accessTokenResponse}`,
400,
);
});

/**
Expand Down Expand Up @@ -254,14 +257,18 @@ const handleFetchJobStatusResponse = (resp, type) => {
if (!isHttpStatusSuccess(marketoReposnseStatus)) {
logger.info('[Network Error]:Failed during fetching job status', { marketoResponse, type });
throw new NetworkError(
'Unable to fetch job status',
`Unable to fetch job status: due to error ${marketoResponse}`,
hydrateStatusForServer(marketoReposnseStatus, 'During fetching job status'),
);
}

if (marketoResponse?.success === false) {
logger.info('[Application Error]Failed during fetching job status', { marketoResponse, type });
throw new RetryableError('Failure during fetching job status', 500, resp);
throw new RetryableError(
`Failure during fetching job status due to error : ${marketoResponse}`,
500,
resp,
);
}

/*
Expand Down Expand Up @@ -394,7 +401,11 @@ const getFieldSchemaMap = async (accessToken, munchkinId) => {
fieldMap[field?.name] = field?.dataType;
});
} else {
throw new RetryableError('Failed to fetch Marketo Field Schema', 500, fieldSchemaMapping);
throw new RetryableError(
`Failed to fetch Marketo Field Schema due to error ${fieldSchemaMapping}`,
500,
fieldSchemaMapping,
);
}
return fieldMap;
};
Expand Down
4 changes: 2 additions & 2 deletions test/__tests__/data/marketo_bulk_upload_jobStatus_output.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
{
"statusCode": 400,
"error": "Unable to fetch job status"
"error": "Unable to fetch job status: due to error "
}
]
},
Expand All @@ -21,7 +21,7 @@
},
{
"statusCode": 400,
"error": "Unable to fetch job status"
"error": "Unable to fetch job status: due to error "
}
]
}
Expand Down

0 comments on commit 3741073

Please sign in to comment.