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

feat: refactor error types - review comments #1697

Merged
merged 5 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion src/v0/destinations/active_campaign/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const errorHandler = (err, message) => {
{
[tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(err.status)
},
err.response.data
err
);
} else {
const httpError = nodeSysErrorToStatus(err.code);
Expand Down
5 changes: 2 additions & 3 deletions src/v0/destinations/af/deleteUsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const { httpPOST } = require("../../../adapters/network");
const { generateUUID } = require("../../util");
const {
ConfigurationError,
TransformationError,
InstrumentationError,
RetryableError
} = require("../../util/errorTypes");
Expand Down Expand Up @@ -90,7 +89,7 @@ const userDeletionHandler = async (userAttributes, config) => {
userAttributes[i].ios_advertising_id
);
if (!response || !response.response) {
throw new TransformationError("Could not get response");
throw new RetryableError("Could not get response");
}
}
if (userAttributeKeys.includes("android_advertising_id")) {
Expand All @@ -107,7 +106,7 @@ const userDeletionHandler = async (userAttributes, config) => {
userAttributes[i].android_advertising_id
);
if (!response || !response.response) {
throw new TransformationError("Could not get response");
throw new RetryableError("Could not get response");
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/v0/destinations/af/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,8 @@ function responseBuilderSimple(payload, message, destination) {
endpoint = `${ENDPOINT}${androidAppId}`;
} else if (os && isAppleFamily(os) && appleAppId) {
endpoint = `${ENDPOINT}id${appleAppId}`;
} else if (!(androidAppId && appleAppId)) {
throw new ConfigurationError("Invalid app endpoint");
} else {
throw new InstrumentationError("Invalid app endpoint");
throw new ConfigurationError("Invalid app endpoint");
}
// if (androidAppId) {
// endpoint = `${ENDPOINT}${androidAppId}`;
Expand Down
7 changes: 4 additions & 3 deletions src/v0/destinations/algolia/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ const set = require("set-value");
const { EventType } = require("../../../constants");
const {
InstrumentationError,
ConfigurationError
ConfigurationError,
PlatformError
} = require("../../util/errorTypes");
const {
getValueFromMessage,
Expand Down Expand Up @@ -73,7 +74,7 @@ const trackResponseBuilder = (message, { Config }) => {
}
if (payload.filters && payload.objectIDs) {
throw new InstrumentationError(
"event cant have both objectIds and filters at the same time."
"event can't have both objectIds and filters at the same time."
);
}
if (payload.eventType === "click") {
Expand Down Expand Up @@ -121,7 +122,7 @@ const process = event => {

const processRouterDest = async (inputs, reqMetadata) => {
if (!Array.isArray(inputs) || inputs.length === 0) {
throw new InstrumentationError("Invalid event array");
throw new PlatformError("Invalid event array");
}

const inputChunks = returnArrayOfSubarrays(inputs, MAX_BATCH_SIZE);
Expand Down
8 changes: 5 additions & 3 deletions src/v0/destinations/bqstream/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const { isHttpStatusSuccess } = require("../../util");
const { proxyRequest } = require("../../../adapters/network");
const {
UnhandledStatusCodeError,
NetworkError
NetworkError,
AbortedError
} = require("../../util/errorTypes");
const tags = require("../../util/tags");

Expand Down Expand Up @@ -119,13 +120,14 @@ const processResponse = ({ dresponse, status } = {}) => {
);
} else if (dresponse.insertErrors && dresponse.insertErrors.length > 0) {
const temp = trimBqStreamResponse(dresponse);
throw new NetworkError(
throw new AbortedError(
"Problem during insert operation",
400,
{
[tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(temp.status || 400)
},
temp.data
temp,
getDestAuthCategory(temp.code)
);
}
throw new UnhandledStatusCodeError(
Expand Down
2 changes: 1 addition & 1 deletion src/v0/destinations/braze/networkHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const responseHandler = (destinationResponse, _dest) => {
) {
throw new NetworkError(
`Request failed for ${DESTINATION} with status: ${status}`,
400,
status,
{
[tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(status)
},
Expand Down
13 changes: 2 additions & 11 deletions src/v0/destinations/campaign_manager/networkHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ const {
const {
AbortedError,
RetryableError,
NetworkError,
InvalidAuthTokenError
NetworkError
} = require("../../util/errorTypes");
const tags = require("../../util/tags");
const get = require("get-value");

/**
* This function helps to detarmine type of error occured. According to the response
* we set authErrorCategory to take decision if we need to refresh the access_token
Expand Down Expand Up @@ -80,14 +79,6 @@ const responseHandler = destinationResponse => {
destinationResponse
};
}
if (getAuthErrCategory(status) === "REFRESH_TOKEN") {
throw new InvalidAuthTokenError(
`Campaign Manager: Retrying as the access token needs to be refreshed`,
500,
destinationResponse,
getAuthErrCategory(status)
);
}

throw new NetworkError(
`Campaign Manager: ${response.error.message} during CAMPAIGN_MANAGER response transformation 3`,
Expand Down
18 changes: 11 additions & 7 deletions src/v0/destinations/delighted/util.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
const axios = require("axios");
const { getDynamicErrorType } = require("../../../adapters/utils/networkUtils");
const { getValueFromMessage } = require("../../util");
const {
NetworkInstrumentationError,
AbortedError,
RetryableError,
InstrumentationError
InstrumentationError,
NetworkError
} = require("../../util/errorTypes");
const { ENDPOINT } = require("./config");
const tags = require("../../util/tags");

const isValidEmail = email => {
const re = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
Expand Down Expand Up @@ -87,12 +90,13 @@ const userValidity = async (channel, Config, userId) => {
errStatus = 400;
}
}
if (errStatus === 500) {
throw new RetryableError(
`Error occurred while checking user : ${errMsg}`
);
}
throw new AbortedError(`Error occurred while checking user : ${errMsg}`);
throw new NetworkError(
`Error occurred while checking user : ${errMsg}`,
errStatus,
{
[tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(errStatus)
}
);
}
};
const eventValidity = (Config, message) => {
Expand Down
23 changes: 4 additions & 19 deletions src/v0/destinations/drip/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ const axios = require("axios");
const { getDynamicErrorType } = require("../../../adapters/utils/networkUtils");
const logger = require("../../../logger");
const { constructPayload, isDefinedAndNotNull } = require("../../util");
const {
NetworkInstrumentationError,
NetworkError
} = require("../../util/errorTypes");
const { NetworkError, AbortedError } = require("../../util/errorTypes");
const { ENDPOINT, productMapping } = require("./config");
const tags = require("../../util/tags");

Expand Down Expand Up @@ -77,26 +74,14 @@ const createUpdateUser = async (finalpayload, Config, basicAuth) => {
if (response) {
return response.status === 200 || response.status === 201;
}
throw new NetworkError(
"Invalid response.",
response.status,
{
[tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(response.status)
},
response
);
throw new AbortedError("Invalid response.");
} catch (error) {
let errMsg = "";
const errStatus = 400;
if (error.response && error.response.data) {
errMsg = JSON.stringify(error.response.data);
}
throw new NetworkError(
`Error occurred while creating or updating user : ${errMsg}`,
errStatus,
{
[tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(errStatus)
}
throw new AbortedError(
`Error occurred while creating or updating user : ${errMsg}`
);
}
};
Expand Down
1 change: 1 addition & 0 deletions src/v0/destinations/fb_custom_audience/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ const processRouterDest = (inputs, reqMetadata) => {
...getEventReqMetadata(input)
}
);
return resp;
}
});
return flattenMap(respList);
Expand Down
5 changes: 3 additions & 2 deletions src/v0/destinations/freshsales/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const createUpdateAccount = async (payload, Config) => {
}
const accountId = accountResponse.response.sales_account?.id;
if (!accountId) {
throw new NetworkInstrumentationError("ails in fetching accountId.");
throw new NetworkInstrumentationError("Fails in fetching accountId.");
}
return accountId;
};
Expand Down Expand Up @@ -182,7 +182,8 @@ const responseBuilderWithContactDetails = async (
const userId = userDetails.response?.contact?.id;
if (!userId) {
throw new NetworkInstrumentationError(
"Failed in fetching userId. Aborting!"
"Failed in fetching userId. Aborting!",
userDetails
);
}
const responseBody = {
Expand Down
2 changes: 1 addition & 1 deletion src/v0/destinations/ga4/networkHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const responseHandler = (destinationResponse, dest) => {
} = response.validationMessages[0];
throw new NetworkError(
`Validation Server Response Handler:: Validation Error for ${dest} of field path :${fieldPath} | ${validationCode}-${description}`,
400,
status,
{
[tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(status)
},
Expand Down
9 changes: 6 additions & 3 deletions src/v0/destinations/gainsight_px/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ const objectExists = async (id, Config, objectType) => {
if (response && response.status === 200) {
return { success: true, err: null };
}
const status = response ? response.status : undefined;
const defStatus = 400;
const status = response ? response.status || defStatus : defStatus;
throw new NetworkError(
err,
status,
Expand Down Expand Up @@ -92,7 +93,8 @@ const createAccount = async (payload, Config) => {
return { success: true, err: null };
}

const status = response?.status || 400;
const defStatus = 400;
const status = response ? response.status || defStatus : defStatus;
throw new NetworkError(
"invalid response while creating account",
status,
Expand Down Expand Up @@ -122,7 +124,8 @@ const updateAccount = async (accountId, payload, Config) => {
if (response && response.status === 204) {
return { success: true, err: null };
}
const status = response ? response.status : undefined;
const defStatus = 400;
const status = response ? response.status || defStatus : defStatus;
throw new NetworkError(
"invalid response while updating account",
status,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ const {
SEARCH_STREAM
} = require("./config");
const {
processAxiosResponse
processAxiosResponse,
getDynamicErrorType
} = require("../../../adapters/utils/networkUtils");
const {
AbortedError,
NetworkInstrumentationError
NetworkInstrumentationError,
NetworkError
} = require("../../util/errorTypes");
const tags = require("../../util/tags");

const conversionCustomVariableCache = new Cache(
CONVERSION_CUSTOM_VARIABLE_CACHE_TTL
Expand Down Expand Up @@ -68,9 +71,14 @@ const getConversionCustomVariable = async (headers, params) => {
let searchStreamResponse = await httpPOST(endpoint, data, requestOptions);
searchStreamResponse = processAxiosResponse(searchStreamResponse);
if (!isHttpStatusSuccess(searchStreamResponse.status)) {
throw new AbortedError(
throw new NetworkError(
`[Google Ads Offline Conversions]:: ${searchStreamResponse.response[0].error.message} during google_ads_offline_conversions response transformation`,
searchStreamResponse.status,
{
[tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(
searchStreamResponse.status
)
},
searchStreamResponse.response,
getAuthErrCategory(searchStreamResponse.status)
);
Expand Down Expand Up @@ -178,10 +186,13 @@ const responseHandler = destinationResponse => {
// non-zero code signifies partialFailure
// Ref - https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto
if (partialFailureError && partialFailureError.code !== 0) {
throw new AbortedError(
throw new NetworkError(
`[Google Ads Offline Conversions]:: partialFailureError - ${partialFailureError.message}`,
400,
partialFailureError.details
status,
{
[tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(status)
},
partialFailureError
);
}

Expand Down
26 changes: 22 additions & 4 deletions src/v0/destinations/marketo/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ const {
formatConfig,
LEAD_LOOKUP_METRIC,
ACTIVITY_METRIC,
FETCH_TOKEN_METRIC,
DESTINATION
FETCH_TOKEN_METRIC
} = require("./config");
const {
addExternalIdToTraits,
Expand All @@ -28,7 +27,7 @@ const {
isDefinedAndNotNull,
generateErrorObject,
checkInvalidRtTfEvents,
handleRtTfSingleEventError
getEventReqMetadata
} = require("../../util");
const Cache = require("../../util/cache");
const { USER_LEAD_CACHE_TTL, AUTH_CACHE_TTL } = require("../../util/constant");
Expand All @@ -44,6 +43,9 @@ const {
ConfigurationError,
UnauthorizedError
} = require("../../util/errorTypes");
const {
client: errNotificationClient
} = require("../../../util/errorNotifier");

const userIdLeadCache = new Cache(USER_LEAD_CACHE_TTL); // 1 day
const emailLeadCache = new Cache(USER_LEAD_CACHE_TTL); // 1 day
Expand Down Expand Up @@ -543,7 +545,23 @@ const processRouterDest = async (inputs, reqMetadata) => {
input.destination
);
} catch (error) {
return handleRtTfSingleEventError(input, error, reqMetadata);
const errObj = generateErrorObject(error);
const resp = getErrorRespEvents(
[input.metadata],
error.status || 500,
error.message || "Error occurred while processing payload.",
errObj.statTags
);
errNotificationClient.notify(
error,
"Router Transformation (event level)",
{
...resp,
...reqMetadata,
...getEventReqMetadata(input)
}
);
return resp;
saikumarrs marked this conversation as resolved.
Show resolved Hide resolved
}
})
);
Expand Down
Loading