Skip to content

Commit

Permalink
feat: introduce new tags and error classes
Browse files Browse the repository at this point in the history
  • Loading branch information
saikumarrs committed Dec 6, 2022
1 parent e36ab45 commit 620b9a7
Show file tree
Hide file tree
Showing 42 changed files with 760 additions and 826 deletions.
7 changes: 4 additions & 3 deletions adapters/utils/networkUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const {
} = require("../../v0/util");
const { TRANSFORMER_METRIC } = require("../../v0/util/constant");
const ErrorBuilder = require("../../v0/util/error");
const tags = require("../../v0/util/tags");

const nodeSysErrorToStatus = code => {
const sysErrorToStatusMap = {
Expand Down Expand Up @@ -75,13 +76,13 @@ const nodeSysErrorToStatus = code => {
// Returns dynamic Meta based on Status Code as Input
const getDynamicMeta = statusCode => {
if (isHttpStatusRetryable(statusCode)) {
return TRANSFORMER_METRIC.MEASUREMENT_TYPE.API.META.RETRYABLE;
return tags.ERROR_TYPES.RETRYABLE;
}
switch (statusCode) {
case 429:
return TRANSFORMER_METRIC.MEASUREMENT_TYPE.API.META.THROTTLED;
return tags.ERROR_TYPES.THROTTLED;
default:
return TRANSFORMER_METRIC.MEASUREMENT_TYPE.API.META.ABORTABLE;
return tags.ERROR_TYPES.ABORTED;
}
};

Expand Down
8 changes: 6 additions & 2 deletions controllers/destinationProxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const stats = require("../util/stats");
const match = require("match-json");
const jsonDiff = require("json-diff");
const logger = require("../logger");
const tags = require("../v0/util/tags");

class DestProxyController {
/**
Expand Down Expand Up @@ -86,8 +87,11 @@ class DestProxyController {

response = generateErrorObject(
err,
destination,
TRANSFORMER_METRIC.TRANSFORMER_STAGE.RESPONSE_TRANSFORM
{
[tags.TAG_NAMES.DEST_TYPE]: destination.toUpperCase(),
[tags.TAG_NAMES.MODULE]: tags.MODULES.DESTINATION,
[tags.TAG_NAMES.FEATURE]: tags.FEATURES.DATA_DELIVERY
}
);
response.message = `[TransformerProxyTest] Error occurred while testing proxy for destination ("${destination}"): "${err.message}"`;
logger.error(response.message);
Expand Down
31 changes: 29 additions & 2 deletions util/errorNotifier/bugsnag.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,22 @@ const {
} = require("rudder-transformer-cdk/build/error/index");
const pkg = require("../../package.json");
const { CustomError } = require("../../v0/util");
const { ApiError, TransformationError } = require("../../v0/util/errors");
const {
DefaultError,
TransformationError,
ConfigurationError,
InstrumentationError,
PlatformError,
OAuthSecretError,
NetworkError,
ThrottledError,
RetryableError,
InvalidAuthTokenError,
AbortedError,
UnhandledStatusCodeError,
UnauthorizedError,
NetworkInstrumentationError
} = require("../../v0/util/errorTypes");

const {
BUGSNAG_API_KEY: apiKey,
Expand All @@ -15,8 +30,20 @@ const {

const errorTypesDenyList = [
CustomError,
ApiError,
DefaultError,
TransformationError,
ConfigurationError,
InstrumentationError,
PlatformError,
OAuthSecretError,
NetworkError,
ThrottledError,
RetryableError,
InvalidAuthTokenError,
AbortedError,
UnhandledStatusCodeError,
UnauthorizedError,
NetworkInstrumentationError,
CDKCustomError,
DataValidationError
];
Expand Down
6 changes: 1 addition & 5 deletions v0/destinations/am/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -973,11 +973,7 @@ const processRouterDest = async inputs => {
input.destination
);
} catch (error) {
const errRes = generateErrorObject(
error,
DESTINATION,
TRANSFORMER_METRIC.TRANSFORMER_STAGE.TRANSFORM
);
const errRes = generateErrorObject(error);
return getErrorRespEvents(
[input.metadata],
error.status || 400,
Expand Down
6 changes: 1 addition & 5 deletions v0/destinations/braze/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -752,11 +752,7 @@ const processRouterDest = async inputs => {
input.destination
);
} catch (error) {
const errObj = generateErrorObject(
error,
DESTINATION,
TRANSFORMER_METRIC.TRANSFORMER_STAGE.TRANSFORM
);
const errObj = generateErrorObject(error);
return getErrorRespEvents(
[input.metadata],
error.status || 400,
Expand Down
21 changes: 5 additions & 16 deletions v0/destinations/campaign_manager/networkHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ const {
const {
processAxiosResponse
} = require("../../../adapters/utils/networkUtils");
const { ApiError } = require("../../util/errors");
const { TRANSFORMER_METRIC } = require("../../util/constant");
const { AbortedError, RetryableError } = require("../../util/errorTypes");

/**
* This function helps to detarmine type of error occured. According to the response
Expand Down Expand Up @@ -54,29 +53,19 @@ const responseHandler = destinationResponse => {
// check for Failures
if (response.hasFailures === true) {
if (checkIfFailuresAreRetryable(response)) {
throw new ApiError(
throw new RetryableError(
`Campaign Manager: Retrying during CAMPAIGN_MANAGER response transformation`,
500,
{
scope: TRANSFORMER_METRIC.MEASUREMENT_TYPE.API.SCOPE,
meta: TRANSFORMER_METRIC.MEASUREMENT_TYPE.API.META.RETRYABLE
},
destinationResponse,
undefined,
"CAMPAIGN_MANAGER"
destinationResponse
);
} else {
// abort message
throw new ApiError(
throw new AbortedError(
`Campaign Manager: Aborting during CAMPAIGN_MANAGER response transformation`,
400,
{
scope: TRANSFORMER_METRIC.MEASUREMENT_TYPE.API.SCOPE,
meta: TRANSFORMER_METRIC.MEASUREMENT_TYPE.API.META.ABORTABLE
},
destinationResponse,
undefined,
"CAMPAIGN_MANAGER"
destinationResponse
);
}
}
Expand Down
27 changes: 9 additions & 18 deletions v0/destinations/clevertap/networkHandler.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const { isHttpStatusSuccess } = require("../../util/index");
const { TRANSFORMER_METRIC } = require("../../util/constant");
const {
proxyRequest,
prepareProxyRequest
Expand All @@ -8,8 +7,8 @@ const {
processAxiosResponse,
getDynamicMeta
} = require("../../../adapters/utils/networkUtils");
const { ApiError } = require("../../util/errors");
const { DESTINATION } = require("./config");
const { NetworkError, AbortedError } = require("../../util/errorTypes");
const tags = require("../../util/tags");

const responseHandler = destinationResponse => {
const message =
Expand All @@ -18,16 +17,13 @@ const responseHandler = destinationResponse => {

// if the response from destination is not a success case build an explicit error
if (!isHttpStatusSuccess(status)) {
throw new ApiError(
`[CleverTap Response Handler] - Request failed with status: ${status}`,
throw new NetworkError(
`Request failed with status: ${status}`,
status,
{
scope: TRANSFORMER_METRIC.MEASUREMENT_TYPE.API.SCOPE,
meta: getDynamicMeta(status)
[tags.TAG_NAMES.ERROR_TYPE]: getDynamicMeta(status)
},
destinationResponse,
undefined,
DESTINATION
destinationResponse
);
}

Expand All @@ -40,16 +36,11 @@ const responseHandler = destinationResponse => {
// }

if (!!response && response.status !== "success") {
throw new ApiError(
`[CleverTap Response Handler] - Request failed with status: ${status}`,
throw new AbortedError(
`Request failed with status: ${status}`,
400,
{
scope: TRANSFORMER_METRIC.MEASUREMENT_TYPE.API.SCOPE,
meta: TRANSFORMER_METRIC.MEASUREMENT_TYPE.API.META.ABORTABLE
},
destinationResponse,
undefined,
DESTINATION
destinationResponse
);
}

Expand Down
40 changes: 10 additions & 30 deletions v0/destinations/clickup/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ const {
getDestinationExternalID,
constructPayload,
defaultPostRequestConfig,
removeUndefinedNullEmptyExclBoolInt,
TransformationError
removeUndefinedNullEmptyExclBoolInt
} = require("../../util");
const {
validatePriority,
Expand All @@ -18,10 +17,12 @@ const {
const {
CONFIG_CATEGORIES,
MAPPING_CONFIG,
createTaskEndPoint,
DESTINATION
createTaskEndPoint
} = require("./config");
const { TRANSFORMER_METRIC } = require("../../util/constant");
const {
TransformationError,
InstrumentationError
} = require("../../util/errorTypes");

const responseBuilder = async (payload, listId, apiToken) => {
if (payload) {
Expand All @@ -37,13 +38,7 @@ const responseBuilder = async (payload, listId, apiToken) => {
}
// fail-safety for developer error
throw new TransformationError(
"Something went wrong while constructing the payload",
400,
{
scope: TRANSFORMER_METRIC.MEASUREMENT_TYPE.TRANSFORMATION.SCOPE,
meta: TRANSFORMER_METRIC.MEASUREMENT_TYPE.TRANSFORMATION.META.BAD_EVENT
},
DESTINATION
"Something went wrong while constructing the payload"
);
};

Expand Down Expand Up @@ -74,15 +69,7 @@ const trackResponseBuilder = async (message, destination) => {

const processEvent = async (message, destination) => {
if (!message.type) {
throw new TransformationError(
"Event type is required",
400,
{
scope: TRANSFORMER_METRIC.MEASUREMENT_TYPE.TRANSFORMATION.SCOPE,
meta: TRANSFORMER_METRIC.MEASUREMENT_TYPE.TRANSFORMATION.META.BAD_EVENT
},
DESTINATION
);
throw new InstrumentationError("Event type is required");
}

checkEventIfUIMapped(message, destination);
Expand All @@ -92,15 +79,8 @@ const processEvent = async (message, destination) => {
return trackResponseBuilder(message, destination);
}

throw new TransformationError(
`Event type "${messageType}" is not supported`,
400,
{
scope: TRANSFORMER_METRIC.MEASUREMENT_TYPE.TRANSFORMATION.SCOPE,
meta:
TRANSFORMER_METRIC.MEASUREMENT_TYPE.TRANSFORMATION.META.INSTRUMENTATION
},
DESTINATION
throw new InstrumentationError(
`Event type "${messageType}" is not supported`
);
};

Expand Down
Loading

0 comments on commit 620b9a7

Please sign in to comment.