Skip to content

Commit

Permalink
chore: refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsSudip committed Jul 1, 2024
1 parent 374a96f commit 157a9ab
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 30 deletions.
58 changes: 29 additions & 29 deletions src/v0/destinations/drip/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ const userExists = async (Config, id, metadata) => {
);
}

const error = httpResponse.response.response;
const error = httpResponse.response?.response;
let errMsg = '';
let errStatus = 400;
if (httpResponse.response.response.status) {
errStatus = httpResponse.response.response.status || 400;
if (error) {
errStatus = error.status || 400;
errMsg = error.data ? JSON.stringify(error.data) : 'error response not found';
}
throw new NetworkError(`Error occurred while checking user : ${errMsg}`, errStatus, {
Expand All @@ -67,39 +67,39 @@ const userExists = async (Config, id, metadata) => {
};

const createUpdateUser = async (finalpayload, Config, basicAuth, metadata) => {
try {
const { httpResponse } = await handleHttpRequest(
'post',
`${ENDPOINT}/v2/${Config.accountId}/subscribers`,
finalpayload,
{
headers: {
Authorization: `Basic ${basicAuth}`,
'Content-Type': JSON_MIME_TYPE,
},
},
{
metadata,
destType: 'drip',
feature: 'transformation',
requestMethod: 'POST',
endpointPath: '/subscribers',
module: 'router',
const { httpResponse } = await handleHttpRequest(
'post',
`${ENDPOINT}/v2/${Config.accountId}/subscribers`,
finalpayload,
{
headers: {
Authorization: `Basic ${basicAuth}`,
'Content-Type': JSON_MIME_TYPE,
},
);
},
{
metadata,
destType: 'drip',
feature: 'transformation',
requestMethod: 'POST',
endpointPath: '/subscribers',
module: 'router',
},
);
if (httpResponse.success) {
const { response } = httpResponse;
if (response) {
return response.status === 200 || response.status === 201;
}
throw new AbortedError('Invalid response.');
} catch ({ destinationResponse }) {
const error = destinationResponse;
let errMsg = '';
if (error.response && error.response.data) {
errMsg = JSON.stringify(error.response.data);
}
throw new AbortedError(`Error occurred while creating or updating user : ${errMsg}`);
}

const error = httpResponse.response;
let errMsg = '';

Check warning on line 98 in src/v0/destinations/drip/util.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/drip/util.js#L97-L98

Added lines #L97 - L98 were not covered by tests
if (error.response && error.response.data) {
errMsg = JSON.stringify(error.response.data);

Check warning on line 100 in src/v0/destinations/drip/util.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/drip/util.js#L100

Added line #L100 was not covered by tests
}
throw new AbortedError(`Error occurred while creating or updating user : ${errMsg}`);

Check warning on line 102 in src/v0/destinations/drip/util.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/drip/util.js#L102

Added line #L102 was not covered by tests
};

const createList = (productList) => {
Expand Down
1 change: 0 additions & 1 deletion src/v0/destinations/trengo/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ const lookupContact = async (term, destination, metadata) => {
throw new NetworkError(
`Inside lookupContact, failed to make request: ${httpResponse.response?.response?.statusText}`,
status,

{
[tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(status),
},
Expand Down

0 comments on commit 157a9ab

Please sign in to comment.