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: add new errorTypes (firehose, freshsales, freshmarketer, ga, ga4) #1660

Merged
merged 8 commits into from
Dec 14, 2022
9 changes: 6 additions & 3 deletions src/v0/destinations/firehose/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ const {
getHashFromArray,
getSuccessRespEvents,
getErrorRespEvents,
CustomError
generateErrorObject
} = require("../../util");
const { ConfigurationError } = require("../../util/errorTypes");

function getDeliveryStreamMapTo(event) {
const { message } = event;
Expand All @@ -25,7 +26,7 @@ function process(event) {
deliveryStreamMapTo
};
}
throw new CustomError("No delivery stream set for this event", 400);
throw new ConfigurationError("No delivery stream set for this event");
}
const processRouterDest = async inputs => {
if (!Array.isArray(inputs) || inputs.length <= 0) {
Expand All @@ -51,14 +52,16 @@ const processRouterDest = async inputs => {
input.destination
);
} catch (error) {
const errObj = generateErrorObject(error);
return getErrorRespEvents(
[input.metadata],
error.response
? error.response.status
: error.code
? error.code
: 400,
error.message || "Error occurred while processing payload."
error.message || "Error occurred while processing payload.",
errObj.statTags
);
}
})
Expand Down
59 changes: 35 additions & 24 deletions src/v0/destinations/freshmarketer/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@ const get = require("get-value");
const { EventType } = require("../../../constants");
const {
defaultRequestConfig,
CustomError,
constructPayload,
ErrorMessage,
defaultPostRequestConfig,
getErrorRespEvents,
getSuccessRespEvents,
getFieldValueFromMessage,
getValidDynamicFormConfig
getValidDynamicFormConfig,
generateErrorObject
} = require("../../util");
const {
InstrumentationError,
NetworkInstrumentationError,
TransformationError
} = require("../../util/errorTypes");

const { CONFIG_CATEGORIES, MAPPING_CONFIG } = require("./config");
const {
Expand Down Expand Up @@ -54,7 +59,7 @@ const identifyResponseBuilder = (message, { Config }) => {

if (!payload) {
// fail-safety for developer error
throw new CustomError(ErrorMessage.FailedToConstructPayload, 400);
throw new TransformationError(ErrorMessage.FailedToConstructPayload);
}
checkNumberDataType(payload);
const response = identifyResponseConfig(Config);
Expand All @@ -71,7 +76,7 @@ const identifyResponseBuilder = (message, { Config }) => {
*/
const trackResponseBuilder = async (message, { Config }, event) => {
if (!event) {
throw new CustomError("Event name is required for track call.", 400);
throw new InstrumentationError("Event name is required for track call.");
}
let payload;

Expand Down Expand Up @@ -104,9 +109,8 @@ const trackResponseBuilder = async (message, { Config }, event) => {
break;
}
default:
throw new CustomError(
`event name ${event} is not supported. Aborting!`,
400
throw new InstrumentationError(
`event name ${event} is not supported. Aborting!`
);
}
response.headers = {
Expand All @@ -127,7 +131,7 @@ const trackResponseBuilder = async (message, { Config }, event) => {
const groupResponseBuilder = async (message, { Config }) => {
const groupType = get(message, "traits.groupType");
if (!groupType) {
throw new CustomError("groupType is required for Group call", 400);
throw new InstrumentationError("groupType is required for Group call");
}
let response;
switch (
Expand All @@ -143,7 +147,7 @@ const groupResponseBuilder = async (message, { Config }) => {
);
if (!payload) {
// fail-safety for developer error
throw new CustomError(ErrorMessage.FailedToConstructPayload, 400);
throw new TransformationError(ErrorMessage.FailedToConstructPayload);
}
checkNumberDataType(payload);
const userEmail = getFieldValueFromMessage(message, "email");
Expand All @@ -164,15 +168,16 @@ const groupResponseBuilder = async (message, { Config }) => {
case "marketing_lists": {
const userEmail = getFieldValueFromMessage(message, "email");
if (!userEmail) {
throw new CustomError(
"email is required for adding in the marketing lists. Aborting!",
400
throw new InstrumentationError(
"email is required for adding in the marketing lists. Aborting!"
);
}
const userDetails = await getContactsDetails(userEmail, Config);
const userId = userDetails.response?.contact?.id;
if (!userId) {
throw new CustomError("Failed in fetching userId. Aborting!", 400);
throw new NetworkInstrumentationError(
"Failed in fetching userId. Aborting!"
);
}
const listName = get(message, "traits.listName");
let listId = get(message, "traits.listId");
Expand All @@ -181,18 +186,21 @@ const groupResponseBuilder = async (message, { Config }) => {
} else if (listName) {
listId = await createOrUpdateListDetails(listName, Config);
if (!listId) {
throw new CustomError("Failed in fetching listId. Aborting!", 400);
throw new NetworkInstrumentationError(
"Failed in fetching listId. Aborting!"
);
}
response = updateContactWithList(userId, listId, Config);
} else {
throw new CustomError("listId or listName is required. Aborting!", 400);
throw new InstrumentationError(
"listId or listName is required. Aborting!"
);
}
break;
}
default:
throw new CustomError(
`groupType ${groupType} is not supported. Aborting!`,
400
throw new InstrumentationError(
`groupType ${groupType} is not supported. Aborting!`
);
}

Expand All @@ -203,7 +211,7 @@ const groupResponseBuilder = async (message, { Config }) => {
function eventMappingHandler(message, destination) {
const event = get(message, "event");
if (!event) {
throw new CustomError("[Freshmarketer] :: Event name is required", 400);
throw new InstrumentationError("Event name is required");
}

let { rudderEventsToFreshmarketerEvents } = destination.Config;
Expand All @@ -229,9 +237,8 @@ function eventMappingHandler(message, destination) {

const processEvent = async (message, destination) => {
if (!message.type) {
throw new CustomError(
"Message Type is not present. Aborting message.",
400
throw new InstrumentationError(
"Message Type is not present. Aborting message."
);
}
let response;
Expand Down Expand Up @@ -265,7 +272,9 @@ const processEvent = async (message, destination) => {
response = await groupResponseBuilder(message, destination);
break;
default:
throw new CustomError(`message type ${messageType} not supported`, 400);
throw new InstrumentationError(
`message type ${messageType} not supported`
);
}
return response;
};
Expand Down Expand Up @@ -298,14 +307,16 @@ const processRouterDest = async inputs => {
input.destination
);
} catch (error) {
const errObj = generateErrorObject(error);
return getErrorRespEvents(
[input.metadata],
error.response
? error.response.status
: error.code
? error.code
: 400,
error.message || "Error occurred while processing payload."
error.message || "Error occurred while processing payload.",
errObj.statTags
);
}
})
Expand Down
Loading