From 3741073ea37e83aa1e6e35c3ccb26d5a41a49617 Mon Sep 17 00:00:00 2001 From: shrouti1507 <60211312+shrouti1507@users.noreply.github.com> Date: Mon, 22 Jan 2024 16:58:29 +0530 Subject: [PATCH] fix: fixing network and default error messages for marketo bulk upload (#3016) * fix: fixing network error messages * fix: fixing default error messages --- .../marketo_bulk_upload/fileUpload.js | 4 ++-- .../destinations/marketo_bulk_upload/poll.js | 2 +- .../destinations/marketo_bulk_upload/util.js | 23 ++++++++++++++----- .../marketo_bulk_upload_jobStatus_output.json | 4 ++-- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/v0/destinations/marketo_bulk_upload/fileUpload.js b/src/v0/destinations/marketo_bulk_upload/fileUpload.js index c7212ff9cb6..4c1679cbfca 100644 --- a/src/v0/destinations/marketo_bulk_upload/fileUpload.js +++ b/src/v0/destinations/marketo_bulk_upload/fileUpload.js @@ -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); diff --git a/src/v0/destinations/marketo_bulk_upload/poll.js b/src/v0/destinations/marketo_bulk_upload/poll.js index 3ad458c5455..97211c47630 100644 --- a/src/v0/destinations/marketo_bulk_upload/poll.js +++ b/src/v0/destinations/marketo_bulk_upload/poll.js @@ -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'), ); } diff --git a/src/v0/destinations/marketo_bulk_upload/util.js b/src/v0/destinations/marketo_bulk_upload/util.js index 7b329a3441b..9661b0e4cb2 100644 --- a/src/v0/destinations/marketo_bulk_upload/util.js +++ b/src/v0/destinations/marketo_bulk_upload/util.js @@ -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), @@ -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":"","token_type":"bearer","expires_in":0,"scope":"dummy@scope.com"} wherein "expires_in":0 denotes that we should refresh the accessToken but its not expired yet. @@ -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, + ); }); /** @@ -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, + ); } /* @@ -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; }; diff --git a/test/__tests__/data/marketo_bulk_upload_jobStatus_output.json b/test/__tests__/data/marketo_bulk_upload_jobStatus_output.json index eac43ee82c8..320ed050c56 100644 --- a/test/__tests__/data/marketo_bulk_upload_jobStatus_output.json +++ b/test/__tests__/data/marketo_bulk_upload_jobStatus_output.json @@ -8,7 +8,7 @@ }, { "statusCode": 400, - "error": "Unable to fetch job status" + "error": "Unable to fetch job status: due to error " } ] }, @@ -21,7 +21,7 @@ }, { "statusCode": 400, - "error": "Unable to fetch job status" + "error": "Unable to fetch job status: due to error " } ] }