Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: error handling in active_campaign #2843

Merged
merged 5 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 6 additions & 47 deletions src/v0/destinations/active_campaign/transform.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
/* eslint-disable array-callback-return */
/* eslint-disable no-empty */
const get = require('get-value');
const {
InstrumentationError,
TransformationError,
NetworkError,
} = require('@rudderstack/integrations-lib');
const { InstrumentationError, TransformationError } = require('@rudderstack/integrations-lib');
const { EventType } = require('../../../constants');
const { CONFIG_CATEGORIES, MAPPING_CONFIG, getHeader } = require('./config');
const {
Expand All @@ -17,8 +13,6 @@
} = require('../../util');
const { errorHandler } = require('./util');
const { httpGET, httpPOST } = require('../../../adapters/network');
const { getDynamicErrorType } = require('../../../adapters/utils/networkUtils');
const tags = require('../../util/tags');

const TOTAL_RECORDS_KEY = 'response.data.meta.total';
const EVENT_DATA_KEY = 'properties.eventData';
Expand Down Expand Up @@ -72,14 +66,7 @@
}
const createdContact = get(res, 'response.data.contact'); // null safe
if (!createdContact) {
throw new NetworkError(
'Unable to Create Contact',
res.response?.status,
{
[tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(res.response?.status),
},
res.response,
);
errorHandler(res.response, 'Failed to create new contact');

Check warning on line 69 in src/v0/destinations/active_campaign/transform.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/active_campaign/transform.js#L69

Added line #L69 was not covered by tests
}
return createdContact.id;
};
Expand Down Expand Up @@ -421,14 +408,7 @@
}

if (res?.response?.status !== 200) {
throw new NetworkError(
'Unable to create event',
res.response?.status,
{
[tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(res.response?.status),
},
res.response,
);
errorHandler(res.response, 'Unable to create event');

Check warning on line 411 in src/v0/destinations/active_campaign/transform.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/active_campaign/transform.js#L411

Added line #L411 was not covered by tests
}

const storedEventsArr = res.response?.data?.eventTrackingEvents;
Expand All @@ -455,14 +435,7 @@
}

if (res.response.status !== 201) {
throw new NetworkError(
'Unable to create event',
res.response.status,
{
[tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(res.response.status),
},
res?.response,
);
errorHandler(res.response, 'Unable to create event');

Check warning on line 438 in src/v0/destinations/active_campaign/transform.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/active_campaign/transform.js#L438

Added line #L438 was not covered by tests
}
}
// Previous operations successfull then
Expand Down Expand Up @@ -499,14 +472,7 @@
}

if (res.response.status !== 200) {
throw new NetworkError(
'Unable to fetch events. Aborting',
res.response.status,
{
[tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(res.response.status),
},
res?.response,
);
errorHandler(res.response, 'Unable to fetch events. Aborting');

Check warning on line 475 in src/v0/destinations/active_campaign/transform.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/active_campaign/transform.js#L475

Added line #L475 was not covered by tests
}

const storedEventsArr = res.response?.data?.eventTrackingEvents;
Expand All @@ -529,14 +495,7 @@
feature: 'transformation',
});
if (res.response?.status !== 201) {
throw new NetworkError(
'Unable to create event. Aborting',
res.response.status,
{
[tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(res.response.status),
},
res.response,
);
errorHandler(res.response, 'Unable to create event. Aborting');

Check warning on line 498 in src/v0/destinations/active_campaign/transform.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/active_campaign/transform.js#L498

Added line #L498 was not covered by tests
}
}

Expand Down
35 changes: 14 additions & 21 deletions src/v0/destinations/active_campaign/util.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,24 @@
const { NetworkError } = require('@rudderstack/integrations-lib');
const {
nodeSysErrorToStatus,
getDynamicErrorType,
processAxiosResponse,
} = require('../../../adapters/utils/networkUtils');
const tags = require('../../util/tags');

const errorHandler = (err, message) => {
if (err.response) {
throw new NetworkError(
`${message} (${err.response?.statusText},${JSON.stringify(err.response?.data)})`,
err.status,
{
[tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(err.status),
},
err,
);
} else {
const httpError = nodeSysErrorToStatus(err.code);
throw new NetworkError(
`${message} ${httpError.message}`,
httpError.status,
{
[tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(httpError.status),
},
err,
);
const errorHandler = (httpCallError, message) => {
const {response, status} = processAxiosResponse(httpCallError);
krishna2020 marked this conversation as resolved.
Show resolved Hide resolved
let msg = message;

Check warning on line 10 in src/v0/destinations/active_campaign/util.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/active_campaign/util.js#L9-L10

Added lines #L9 - L10 were not covered by tests
if (response) {
msg = `${message} (${httpCallError.response?.statusText},${JSON.stringify(response)})`;

Check warning on line 12 in src/v0/destinations/active_campaign/util.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/active_campaign/util.js#L12

Added line #L12 was not covered by tests
}
throw new NetworkError(

Check warning on line 14 in src/v0/destinations/active_campaign/util.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/active_campaign/util.js#L14

Added line #L14 was not covered by tests
msg,
status,
{
[tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(status),
},
response,
);
};

const offsetLimitVarPath = 'response.data.meta.total';
Expand Down
Loading