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: new error types for destinations(mixpanel, monetate, monday, moengage, minio) #1667

Merged
merged 2 commits into from
Dec 14, 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
27 changes: 13 additions & 14 deletions src/v0/destinations/moengage/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ const {
flattenJson,
getSuccessRespEvents,
getErrorRespEvents,
CustomError,
isAppleFamily
} = require("../../util");
const {
ConfigurationError,
TransformationError,
InstrumentationError
} = require("../../util/errorTypes");

function responseBuilderSimple(message, category, destination) {
const payload = constructPayload(message, MAPPING_CONFIG[category.name]);
Expand All @@ -35,7 +39,7 @@ function responseBuilderSimple(message, category, destination) {
response.endpoint = `${endpointIND[category.type]}${apiId}`;
break;
default:
throw new CustomError("The region is not valid", 400);
throw new ConfigurationError("The region is not valid");
}
response.method = defaultPostRequestConfig.requestMethod;
response.headers = {
Expand Down Expand Up @@ -89,23 +93,20 @@ function responseBuilderSimple(message, category, destination) {
}
break;
default:
throw new CustomError("Call type is not valid", 400);
throw new InstrumentationError("Call type is not valid");
saikumarrs marked this conversation as resolved.
Show resolved Hide resolved
}

response.body.JSON = removeUndefinedAndNullValues(payload);
} else {
// fail-safety for developer error
throw new CustomError("Payload could not be constructed", 400);
throw new TransformationError("Payload could not be constructed");
}
return response;
}

const processEvent = (message, destination) => {
if (!message.type) {
throw new CustomError(
"Message Type is not present. Aborting message.",
400
);
throw new InstrumentationError("Event type is required");
}

const messageType = message.type.toLowerCase();
Expand Down Expand Up @@ -137,7 +138,9 @@ const processEvent = (message, destination) => {
response = responseBuilderSimple(message, category, destination);
break;
default:
throw new CustomError("Message type not supported", 400);
throw new InstrumentationError(
`Event type ${messageType} is not supported`
);
}

return response;
Expand Down Expand Up @@ -173,11 +176,7 @@ const processRouterDest = async inputs => {
} catch (error) {
return getErrorRespEvents(
[input.metadata],
error.response
? error.response.status
: error.code
? error.code
: 400,
error.response?.status || error.code || 400,
error.message || "Error occurred while processing payload."
);
}
Expand Down
36 changes: 18 additions & 18 deletions src/v0/destinations/monday/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ const {
defaultRequestConfig,
defaultPostRequestConfig,
removeUndefinedAndNullValues,
CustomError,
getErrorRespEvents,
getSuccessRespEvents,
getDestinationExternalID
} = require("../../util");
const {
ConfigurationError,
TransformationError,
InstrumentationError
} = require("../../util/errorTypes");

const responseBuilder = (payload, endpoint, apiToken) => {
if (payload) {
Expand All @@ -28,9 +32,8 @@ const responseBuilder = (payload, endpoint, apiToken) => {
response.body.JSON = removeUndefinedAndNullValues(payload);
return response;
}
throw new CustomError(
"Monday]: Payload could not be populated due to wrong input",
400
throw new TransformationError(
"Payload could not be populated due to wrong input"
);
};

Expand All @@ -47,21 +50,19 @@ const trackResponseBuilder = async (message, { Config }) => {
boardId = Config.boardId;
}
if (!boardId) {
throw new CustomError("Monday]: boardId is a required field", 400);
throw new ConfigurationError("boardId is a required field");
}
const event = get(message, "event");

if (!event) {
throw new CustomError(
"[Monday]: event is not present in the input payloads",
400
throw new InstrumentationError(
"event is not present in the input payloads"
);
}

if (!checkAllowedEventNameFromUI(event, Config)) {
throw new CustomError(
"[Monday]:: Event Discarded. To allow this event, add this in Allowlist",
400
throw new ConfigurationError(
"Event Discarded. To allow this event, add this in Allowlist"
);
}
const endpoint = ENDPOINT;
Expand All @@ -75,13 +76,10 @@ const trackResponseBuilder = async (message, { Config }) => {

const processEvent = async (message, destination) => {
if (!message.type) {
throw new CustomError(
"Message Type is not present. Aborting message.",
400
);
throw new InstrumentationError("Event type is required");
}
if (!destination.Config.apiToken) {
throw new CustomError("[Monday]: apiToken is a required field", 400);
throw new ConfigurationError("ApiToken is a required field");
}
const messageType = message.type.toLowerCase();
let response;
Expand All @@ -90,7 +88,9 @@ const processEvent = async (message, destination) => {
response = await trackResponseBuilder(message, destination);
break;
default:
throw new CustomError(`Message type ${messageType} not supported`, 400);
throw new InstrumentationError(
`Event type ${messageType} is not supported`
);
}
return response;
};
Expand Down Expand Up @@ -125,7 +125,7 @@ const processRouterDest = async inputs => {
} catch (error) {
return getErrorRespEvents(
[input.metadata],
error.response ? error.response.status : error.code || 400,
error.response?.status || error.code || 400,
error.message || "Error occurred while processing payload."
);
}
Expand Down
32 changes: 23 additions & 9 deletions src/v0/destinations/monday/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@ const { httpPOST } = require("../../../adapters/network");
const {
processAxiosResponse
} = require("../../../adapters/utils/networkUtils");
const { CustomError, getDestinationExternalID } = require("../../util");
const { getDestinationExternalID } = require("../../util");
const {
NetworkError,
ConfigurationError,
InstrumentationError
} = require("../../util/errorTypes");
const { getDynamicErrorType } = require("../../../adapters/utils/networkUtils");
const tags = require("../../util/tags");

/**
* This function is taking the board(received from the lookup call) and groupTitle as parameter
Expand All @@ -23,7 +30,9 @@ const getGroupId = (groupTitle, board) => {
if (groupId) {
return groupId;
}
throw new CustomError(`Group ${groupTitle} doesn't exist in the board`, 400);
throw new ConfigurationError(
`Group ${groupTitle} doesn't exist in the board`
);
};

/**
Expand All @@ -44,9 +53,8 @@ const getColumnId = (columnTitle, board) => {
if (columnId) {
return columnId;
}
throw new CustomError(
`Column ${columnTitle} doesn't exist in the board`,
400
throw new ConfigurationError(
`Column ${columnTitle} doesn't exist in the board`
);
};

Expand Down Expand Up @@ -189,10 +197,16 @@ const getBoardDetails = async (url, boardID, apiToken) => {
);
const boardDeatailsResponse = processAxiosResponse(clientResponse);
if (boardDeatailsResponse.status !== 200) {
throw new CustomError(
throw new NetworkError(
`The lookup call could not be completed with the error:
${JSON.stringify(boardDeatailsResponse.response)}`, // Recheck this
boardDeatailsResponse.status
${JSON.stringify(boardDeatailsResponse.response)}`,
boardDeatailsResponse.status,
{
[tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(
boardDeatailsResponse.status
)
},
boardDeatailsResponse.response
);
}
return boardDeatailsResponse;
Expand Down Expand Up @@ -220,7 +234,7 @@ const populatePayload = (message, Config, boardDeatailsResponse) => {
);
if (groupTitle) {
if (!message.properties?.name) {
throw new CustomError(`Item name is required to create an item`, 400);
throw new InstrumentationError("Item name is required to create an item");
}
const groupId = getGroupId(
groupTitle,
Expand Down
52 changes: 21 additions & 31 deletions src/v0/destinations/monetate/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@ const {
removeUndefinedValues,
getErrorRespEvents,
getSuccessRespEvents,
CustomError,
isDefinedAndNotNull
} = require("../../util");
const { EventType } = require("../../../constants");

const { ENDPOINT, mappingConfig } = require("./config");
const { InstrumentationError } = require("../../util/errorTypes");

const createObject = type => {
if (!type) {
throw new CustomError("[createObject] type not defined", 400);
throw new InstrumentationError("[createObject] type not defined");
}
// TODO: check if default makes sense
let retObj = {};
Expand All @@ -27,6 +26,8 @@ const createObject = type => {
case "object":
retObj = {};
break;
default:
break;
}
return retObj;
};
Expand Down Expand Up @@ -157,9 +158,8 @@ const constructPayload = (message, mappingJson) => {
}
} else if (required) {
// throw error if reqired value is missing
throw new CustomError(
`Missing required value from ${JSON.stringify(sourceKeys)}`,
400
throw new InstrumentationError(
`Missing required value from ${JSON.stringify(sourceKeys)}`
);
}
});
Expand Down Expand Up @@ -194,9 +194,8 @@ function track(message, destination) {
]
});
} else {
throw new CustomError(
"'product_id' is a required field for Product Viewed",
400
throw new InstrumentationError(
"'product_id' is a required field for Product Viewed"
);
}
} else if (evName === "Product List Viewed") {
Expand All @@ -205,9 +204,8 @@ function track(message, destination) {
product => product.product_id
);
if (viewedProducts.length !== properties.products.length) {
throw new CustomError(
"'product_id' is a required field for all products for Product List Viewed",
400
throw new InstrumentationError(
"'product_id' is a required field for all products for Product List Viewed"
);
}
rawPayload.events.push({
Expand All @@ -217,9 +215,8 @@ function track(message, destination) {
)
});
} else {
throw new CustomError(
"'products' missing or not array in Product List Viewed",
400
throw new InstrumentationError(
"'products' missing or not array in Product List Viewed"
);
}
} else if (evName === "Product Added") {
Expand Down Expand Up @@ -248,9 +245,8 @@ function track(message, destination) {
]
});
} else {
throw new CustomError(
"'product_id', 'quantity', 'cart_value' are required fields and 'quantity' should be a number for Product Added",
400
throw new InstrumentationError(
"'product_id', 'quantity', 'cart_value' are required fields and 'quantity' should be a number for Product Added"
);
}
} else if (evName === "Cart Viewed") {
Expand All @@ -264,9 +260,8 @@ function track(message, destination) {
product.product_id
);
if (cartProducts.length !== properties.products.length) {
throw new CustomError(
"'quantity', 'price' and 'product_id' are required fields and 'quantity' and 'price' should be a number for all products for Cart Viewed",
400
throw new InstrumentationError(
"'quantity', 'price' and 'product_id' are required fields and 'quantity' and 'price' should be a number for all products for Cart Viewed"
);
}
rawPayload.events.push({
Expand Down Expand Up @@ -298,9 +293,8 @@ function track(message, destination) {
product.product_id
);
if (purchaseLines.length !== products.length) {
throw new CustomError(
"'quantity', 'price' and 'product_id' are required fields and 'quantity' and 'price' should be a number for all products for Order Completed",
400
throw new InstrumentationError(
"'quantity', 'price' and 'product_id' are required fields and 'quantity' and 'price' should be a number for all products for Order Completed"
);
}
rawPayload.events.push({
Expand Down Expand Up @@ -368,10 +362,10 @@ function process(event) {
case EventType.SCREEN:
return screen(event.message, event.destination);
default:
throw new CustomError(`Message type ${evType} not supported`, 400);
throw new InstrumentationError(`Event type ${evType} is not supported`);
}
}
throw new CustomError("Message type missing from event", 400);
throw new InstrumentationError("Event type is required");
}

const processRouterDest = async inputs => {
Expand Down Expand Up @@ -400,11 +394,7 @@ const processRouterDest = async inputs => {
} catch (error) {
return getErrorRespEvents(
[input.metadata],
error.response
? error.response.status
: error.code
? error.code
: 400,
error.response?.status || error.code || 400,
error.message || "Error occurred while processing payload."
);
}
Expand Down
Loading