From d132638bd6669eaa8dd955273715e04885f938bf Mon Sep 17 00:00:00 2001 From: ujjwal-ab Date: Fri, 9 Dec 2022 07:49:50 +0530 Subject: [PATCH 1/8] feat:[algolia] add new error types --- src/v0/destinations/algolia/transform.js | 36 +++++++++++++----------- src/v0/destinations/algolia/util.js | 17 +++++------ 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/src/v0/destinations/algolia/transform.js b/src/v0/destinations/algolia/transform.js index 32af92530c..7f872e1078 100644 --- a/src/v0/destinations/algolia/transform.js +++ b/src/v0/destinations/algolia/transform.js @@ -1,7 +1,10 @@ const set = require("set-value"); const { EventType } = require("../../../constants"); const { - CustomError, + InstrumentationError, + ConfigurationError +} = require("../../util/errorTypes"); +const { getValueFromMessage, constructPayload, defaultRequestConfig, @@ -24,7 +27,7 @@ const { const trackResponseBuilder = (message, { Config }) => { let event = getValueFromMessage(message, "event"); if (!event) { - throw new CustomError("event is required for track call", 400); + throw new InstrumentationError("event is required for track call"); } event = event.trim().toLowerCase(); let payload = constructPayload(message, trackMapping); @@ -34,7 +37,7 @@ const trackResponseBuilder = (message, { Config }) => { getValueFromMessage(message, "properties.eventType") || eventMapping[event]; if (!payload.eventType) { - throw new CustomError("eventType is mandatory for track call", 400); + throw new InstrumentationError("eventType is mandatory for track call"); } payload = genericpayloadValidator(payload); @@ -57,21 +60,19 @@ const trackResponseBuilder = (message, { Config }) => { } // making size of object list and position list equal if (posLen > 0 && objLen > 0 && posLen !== objLen) { - throw new CustomError( - "length of objectId and position should be equal", - 400 + throw new InstrumentationError( + "length of objectId and position should be equal" ); } } } // for all events either filter or objectID should be there if (!payload.filters && !payload.objectIDs) { - throw new CustomError("Either filters or objectIds is required.", 400); + throw new InstrumentationError("Either filters or objectIds is required."); } if (payload.filters && payload.objectIDs) { - throw new CustomError( - "event can’t have both objectIds and filters at the same time.", - 400 + throw new InstrumentationError( + "event can’t have both objectIds and filters at the same time." ); } if (payload.eventType === "click") { @@ -91,17 +92,16 @@ const trackResponseBuilder = (message, { Config }) => { const process = event => { const { message, destination } = event; if (!message.type) { - throw new CustomError( - "message Type is not present. Aborting message.", - 400 + throw new InstrumentationError( + "message Type is not present. Aborting message." ); } if (!destination.Config.apiKey) { - throw new CustomError("Invalid Api Key", 400); + throw new ConfigurationError("Invalid Api Key"); } if (!destination.Config.applicationId) { - throw new CustomError("Invalid Application Id", 400); + throw new ConfigurationError("Invalid Application Id"); } const messageType = message.type.toLowerCase(); @@ -111,14 +111,16 @@ const process = event => { response = trackResponseBuilder(message, destination); break; default: - throw new CustomError(`message type ${messageType} not supported`, 400); + throw new InstrumentationError( + `message type ${messageType} not supported` + ); } return response; }; const processRouterDest = async inputs => { if (!Array.isArray(inputs) || inputs.length === 0) { - throw new CustomError("Invalid event array", 400); + throw new InstrumentationError("Invalid event array"); } const inputChunks = returnArrayOfSubarrays(inputs, MAX_BATCH_SIZE); diff --git a/src/v0/destinations/algolia/util.js b/src/v0/destinations/algolia/util.js index 226a753489..36ad005486 100644 --- a/src/v0/destinations/algolia/util.js +++ b/src/v0/destinations/algolia/util.js @@ -1,5 +1,5 @@ const logger = require("../../../logger"); -const { CustomError } = require("../../util"); +const { InstrumentationError } = require("../../util/errorTypes"); const { EVENT_TYPES } = require("./config"); /** @@ -28,9 +28,8 @@ const genericpayloadValidator = payload => { const updatedPayload = payload; updatedPayload.eventType = payload.eventType.trim().toLowerCase(); if (!EVENT_TYPES.includes(payload.eventType)) { - throw new CustomError( - "eventType can be either click, view or conversion", - 400 + throw new InstrumentationError( + "eventType can be either click, view or conversion" ); } if (payload.filters && !Array.isArray(payload.filters)) { @@ -116,9 +115,8 @@ const clickPayloadValidator = payload => { } if (payload.objectIDs && payload.positions) { if (payload.objectIDs.length !== payload.positions.length) { - throw new CustomError( - "length of objectId and position should be equal", - 400 + throw new InstrumentationError( + "length of objectId and position should be equal" ); } } @@ -127,9 +125,8 @@ const clickPayloadValidator = payload => { (payload.positions && !payload.queryID) || (!payload.positions && payload.queryID) ) { - throw new CustomError( - "for click eventType either both positions and queryId should be present or none", - 400 + throw new InstrumentationError( + "for click eventType either both positions and queryId should be present or none" ); } } From b9ed5209335d4869cca5ab580466873ed2c3f696 Mon Sep 17 00:00:00 2001 From: ujjwal-ab Date: Fri, 9 Dec 2022 08:08:53 +0530 Subject: [PATCH 2/8] feat:[appcues] add new error types --- src/v0/destinations/appcues/transform.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/v0/destinations/appcues/transform.js b/src/v0/destinations/appcues/transform.js index dacb5bbd8e..3af67242eb 100644 --- a/src/v0/destinations/appcues/transform.js +++ b/src/v0/destinations/appcues/transform.js @@ -8,8 +8,9 @@ const { removeUndefinedAndNullAndEmptyValues, getSuccessRespEvents, getErrorRespEvents, - CustomError + generateErrorObject } = require("../../util"); +const { InstrumentationError } = require("../../util/errorTypes"); const { ConfigCategory, mappingConfig, getEndpoint } = require("./config"); @@ -70,16 +71,14 @@ function process(event) { const { message, destination } = event; if (!message.type) { - throw new CustomError( - "Message Type is not present. Aborting message.", - 400 + throw new InstrumentationError( + "Message Type is not present. Aborting message." ); } if (!message.userId) { - throw new CustomError( - "User id is absent. Aborting event as userId is mandatory for Appcues", - 400 + throw new InstrumentationError( + "User id is absent. Aborting event as userId is mandatory for Appcues" ); } @@ -113,7 +112,7 @@ function process(event) { getEndpoint(destination.Config.accountId, message.userId) ); default: - throw new CustomError("Message type is not supported", 400); + throw new InstrumentationError("Message type is not supported"); } } @@ -141,6 +140,7 @@ const processRouterDest = async inputs => { input.destination ); } catch (error) { + const errRes = generateErrorObject(error); return getErrorRespEvents( [input.metadata], error.response @@ -148,7 +148,8 @@ const processRouterDest = async inputs => { : error.code ? error.code : 400, - error.message || "Error occurred while processing payload." + error.message || "Error occurred while processing payload.", + errRes.statTags ); } }) From 10182f5738bb4f318c491fdddff745732708bd0c Mon Sep 17 00:00:00 2001 From: ujjwal-ab Date: Fri, 9 Dec 2022 08:35:35 +0530 Subject: [PATCH 3/8] feat: add new error types --- .../destinations/attentive_tag/transform.js | 53 ++++++++++--------- .../__tests__/data/algolia_router_output.json | 6 +-- 2 files changed, 31 insertions(+), 28 deletions(-) diff --git a/src/v0/destinations/attentive_tag/transform.js b/src/v0/destinations/attentive_tag/transform.js index 78f217b858..48248c1bd5 100644 --- a/src/v0/destinations/attentive_tag/transform.js +++ b/src/v0/destinations/attentive_tag/transform.js @@ -8,18 +8,21 @@ const { defaultPostRequestConfig, removeUndefinedAndNullValues, getIntegrationsObj, - CustomError, getErrorRespEvents, getSuccessRespEvents, - isDefinedAndNotNullAndNotEmpty + isDefinedAndNotNullAndNotEmpty, + generateErrorObject } = require("../../util"); const { getDestinationItemProperties, getExternalIdentifiersMapping, - getUserExistence, getPropertiesKeyValidation, validateTimestamp } = require("./util"); +const { + InstrumentationError, + ConfigurationError +} = require("../../util/errorTypes"); const responseBuilder = (payload, apiKey, endpoint) => { if (payload) { @@ -38,7 +41,8 @@ const responseBuilder = (payload, apiKey, endpoint) => { const identifyResponseBuilder = (message, { Config }) => { const { apiKey } = Config; let { signUpSourceId } = Config; - let endpoint, payload; + let endpoint; + let payload; const integrationsObj = getIntegrationsObj(message, "attentive_tag"); if (integrationsObj) { // Overriding signupSourceId if present in integrations object @@ -81,7 +85,7 @@ const identifyResponseBuilder = (message, { Config }) => { mappingConfig[ConfigCategory.IDENTIFY.name] ); if (!signUpSourceId) { - throw new CustomError( + throw new ConfigurationError( "[Attentive Tag]: SignUp Source Id is required for subscribe event" ); } @@ -96,9 +100,8 @@ const identifyResponseBuilder = (message, { Config }) => { (!isDefinedAndNotNullAndNotEmpty(payload.user.email) && !isDefinedAndNotNullAndNotEmpty(payload.user.phone)) ) { - throw new CustomError( - "[Attentive Tag] :: Either email or phone is required", - 400 + throw new InstrumentationError( + "[Attentive Tag] :: Either email or phone is required" ); } return responseBuilder(payload, apiKey, endpoint); @@ -107,14 +110,16 @@ const identifyResponseBuilder = (message, { Config }) => { const trackResponseBuilder = (message, { Config }) => { const { apiKey } = Config; let endpoint; - let event = get(message, "event"); + let payload; + const event = get(message, "event"); if (!event) { - throw new CustomError("[Attentive Tag] :: Event name is not present", 400); + throw new InstrumentationError( + "[Attentive Tag] :: Event name is not present" + ); } if (!validateTimestamp(getFieldValueFromMessage(message, "timestamp"))) { - throw new CustomError( - "[Attentive_Tag]: Events must be sent within 12 hours of their occurrence.", - 400 + throw new InstrumentationError( + "[Attentive_Tag]: Events must be sent within 12 hours of their occurrence." ); } switch ( @@ -169,9 +174,8 @@ const trackResponseBuilder = (message, { Config }) => { endpoint = ConfigCategory.TRACK.endpoint; payload.type = get(message, "event"); if (!getPropertiesKeyValidation(payload)) { - throw new CustomError( - "[Attentive Tag]:The event name contains characters which is not allowed", - 400 + throw new InstrumentationError( + "[Attentive Tag]:The event name contains characters which is not allowed" ); } payload.externalIdentifiers = getExternalIdentifiersMapping(message); @@ -182,9 +186,8 @@ const trackResponseBuilder = (message, { Config }) => { (!isDefinedAndNotNullAndNotEmpty(payload.user.email) && !isDefinedAndNotNullAndNotEmpty(payload.user.phone)) ) { - throw new CustomError( - "[Attentive Tag] :: Either email or phone is required", - 400 + throw new InstrumentationError( + "[Attentive Tag] :: Either email or phone is required" ); } return responseBuilder(payload, apiKey, endpoint); @@ -192,13 +195,13 @@ const trackResponseBuilder = (message, { Config }) => { const processEvent = (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." ); } const messageType = message.type.toLowerCase(); + let response; switch (messageType) { case EventType.IDENTIFY: response = identifyResponseBuilder(message, destination); @@ -207,7 +210,7 @@ const processEvent = (message, destination) => { response = trackResponseBuilder(message, destination); break; default: - throw new CustomError("Message type not supported", 400); + throw new InstrumentationError("Message type not supported"); } return response; }; @@ -240,6 +243,7 @@ const processRouterDest = inputs => { input.destination ); } catch (error) { + const errRes = generateErrorObject(error); return getErrorRespEvents( [input.metadata], error.response @@ -247,7 +251,8 @@ const processRouterDest = inputs => { : error.code ? error.code : 400, - error.message || "Error occurred while processing payload." + error.message || "Error occurred while processing payload.", + errRes.statTags ); } }) diff --git a/test/__tests__/data/algolia_router_output.json b/test/__tests__/data/algolia_router_output.json index 17ed8c3842..9391a0fc32 100644 --- a/test/__tests__/data/algolia_router_output.json +++ b/test/__tests__/data/algolia_router_output.json @@ -6,10 +6,8 @@ "statusCode": 400, "error": "Missing required value from \"properties.index\"", "statTags": { - "destType": "ALGOLIA", - "stage": "transform", - "scope": "transformation", - "meta": "handled" + "errorCategory": "dataValidation", + "errorType": "instrumentation" } }, { From 5dfaa26c7b844736b587e16ffb3587d1624355d9 Mon Sep 17 00:00:00 2001 From: ujjwal-ab Date: Fri, 9 Dec 2022 08:37:25 +0530 Subject: [PATCH 4/8] feat: add new error types --- src/v0/destinations/attribution/transform.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/v0/destinations/attribution/transform.js b/src/v0/destinations/attribution/transform.js index 1a51777f1a..5b59e0c859 100644 --- a/src/v0/destinations/attribution/transform.js +++ b/src/v0/destinations/attribution/transform.js @@ -3,9 +3,12 @@ const { defaultPostRequestConfig, defaultRequestConfig, removeUndefinedAndNullValues, - getFieldValueFromMessage, - CustomError + getFieldValueFromMessage } = require("../../util"); +const { + InstrumentationError, + ConfigurationError +} = require("../../util/errorTypes"); function responseBuilderSimple(payload, attributionConfig) { const basicAuth = Buffer.from(`${attributionConfig.writeKey}:`).toString( @@ -28,7 +31,7 @@ function responseBuilderSimple(payload, attributionConfig) { function getTransformedJSON(message) { if (!message.type) { - throw new CustomError("Event type is required"); + throw new InstrumentationError("Event type is required"); } const traits = getFieldValueFromMessage(message, "traits"); @@ -47,7 +50,7 @@ function getTransformedJSON(message) { function getAttributionConfig(destination) { const { writeKey } = destination.Config; if (!writeKey) { - throw new CustomError("No writeKey in config"); + throw new ConfigurationError("No writeKey in config"); } return { writeKey }; From 6899dfbcde541e207008af8907c778d01e6b98fc Mon Sep 17 00:00:00 2001 From: ujjwal-ab Date: Fri, 9 Dec 2022 08:45:20 +0530 Subject: [PATCH 5/8] feat:[autopilot] add new error types --- src/v0/destinations/autopilot/transform.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/v0/destinations/autopilot/transform.js b/src/v0/destinations/autopilot/transform.js index 426cb85bc3..c7b65e57c7 100644 --- a/src/v0/destinations/autopilot/transform.js +++ b/src/v0/destinations/autopilot/transform.js @@ -10,9 +10,13 @@ const { removeUndefinedAndNullValues, getSuccessRespEvents, getErrorRespEvents, - CustomError + generateErrorObject } = require("../../util"); const ErrorBuilder = require("../../util/error"); +const { + InstrumentationError, + TransformationError +} = require("../../util/errorTypes"); const identifyFields = [ "email", @@ -86,12 +90,12 @@ function responseBuilderSimple(message, category, destination) { return response; } // fail-safety for developer error - throw new CustomError("Payload could not be constructed", 400); + throw new TransformationError("Payload could not be constructed"); } const processEvent = (message, destination) => { if (!message.type) { - throw new CustomError("invalid message type for autopilot", 400); + throw new InstrumentationError("invalid message type for autopilot"); } const messageType = message.type; let category; @@ -103,9 +107,8 @@ const processEvent = (message, destination) => { category = CONFIG_CATEGORIES.TRACK; break; default: - throw new CustomError( - `message type ${messageType} not supported for autopilot`, - 400 + throw new InstrumentationError( + `message type ${messageType} not supported for autopilot` ); } @@ -140,6 +143,7 @@ const processRouterDest = async inputs => { input.destination ); } catch (error) { + const errRes = generateErrorObject(error); return getErrorRespEvents( [input.metadata], error.response @@ -147,7 +151,8 @@ const processRouterDest = async inputs => { : error.code ? error.code : 400, - error.message || "Error occurred while processing payload." + error.message || "Error occurred while processing payload.", + errRes.statTags ); } }) From 952a9214a3035e50b04599a1619c3046967ba63c Mon Sep 17 00:00:00 2001 From: ujjwal-ab Date: Fri, 9 Dec 2022 10:35:05 +0530 Subject: [PATCH 6/8] feat: add new error types --- src/v0/destinations/am/transform.js | 40 +++-------------------------- 1 file changed, 4 insertions(+), 36 deletions(-) diff --git a/src/v0/destinations/am/transform.js b/src/v0/destinations/am/transform.js index 339cc1c064..29982f234b 100644 --- a/src/v0/destinations/am/transform.js +++ b/src/v0/destinations/am/transform.js @@ -29,9 +29,7 @@ const { isAppleFamily, isDefinedAndNotNullAndNotEmpty } = require("../../util"); -const ErrorBuilder = require("../../util/error"); const { - DESTINATION, BASE_URL, BASE_URL_EU, ConfigCategory, @@ -42,6 +40,7 @@ const { const AMUtils = require("./utils"); const logger = require("../../../logger"); +const { InstrumentationError } = require("../../util/errorTypes"); const AMBatchSizeLimit = 20 * 1024 * 1024; // 20 MB const AMBatchEventLimit = 500; // event size limit from sdk is 32KB => 15MB @@ -610,18 +609,7 @@ function processSingleMessage(message, destination) { groupInfo.group_properties = groupTraits; } else { logger.debug("Group call parameters are not valid"); - throw new ErrorBuilder() - .setStatus(400) - .setMessage("Group call parameters are not valid") - .setStatTags({ - destType: DESTINATION, - stage: TRANSFORMER_METRIC.TRANSFORMER_STAGE.TRANSFORM, - scope: TRANSFORMER_METRIC.MEASUREMENT_TYPE.TRANSFORMATION.SCOPE, - meta: - TRANSFORMER_METRIC.MEASUREMENT_TYPE.TRANSFORMATION.META - .INSTRUMENTATION - }) - .build(); + throw new InstrumentationError("Group call parameters are not valid"); } } break; @@ -635,17 +623,7 @@ function processSingleMessage(message, destination) { case EventType.TRACK: evType = message.event; if (!isDefinedAndNotNullAndNotEmpty(evType)) { - throw new ErrorBuilder() - .setStatus(400) - .setMessage("message type not defined") - .setStatTags({ - destType: DESTINATION, - stage: TRANSFORMER_METRIC.TRANSFORMER_STAGE.TRANSFORM, - scope: TRANSFORMER_METRIC.MEASUREMENT_TYPE.TRANSFORMATION.SCOPE, - meta: - TRANSFORMER_METRIC.MEASUREMENT_TYPE.TRANSFORMATION.META.BAD_EVENT - }) - .build(); + throw new InstrumentationError("message type not defined"); } if ( message.properties && @@ -661,17 +639,7 @@ function processSingleMessage(message, destination) { break; default: logger.debug("could not determine type"); - throw new ErrorBuilder() - .setStatus(400) - .setMessage("message type not supported") - .setStatTags({ - destType: DESTINATION, - stage: TRANSFORMER_METRIC.TRANSFORMER_STAGE.TRANSFORM, - scope: TRANSFORMER_METRIC.MEASUREMENT_TYPE.TRANSFORMATION.SCOPE, - meta: - TRANSFORMER_METRIC.MEASUREMENT_TYPE.TRANSFORMATION.META.BAD_EVENT - }) - .build(); + throw new InstrumentationError("message type not supported"); } return responseBuilderSimple( groupInfo, From 41b7d78c328eea7ee9fb9f174094660eee0e3e01 Mon Sep 17 00:00:00 2001 From: ujjwal-ab Date: Wed, 14 Dec 2022 16:08:24 +0530 Subject: [PATCH 7/8] feat: update new error types --- src/v0/destinations/am/deleteUsers.js | 34 ++++++++++++++++------- src/v0/destinations/attentive_tag/util.js | 14 ++++------ 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/src/v0/destinations/am/deleteUsers.js b/src/v0/destinations/am/deleteUsers.js index 51325fc093..ac1e5f10f6 100644 --- a/src/v0/destinations/am/deleteUsers.js +++ b/src/v0/destinations/am/deleteUsers.js @@ -1,21 +1,29 @@ const btoa = require("btoa"); const { httpSend } = require("../../../adapters/network"); -const { CustomError } = require("../../util"); +const { getDynamicErrorType } = require("../../../adapters/utils/networkUtils"); + +const { + NetworkError, + RetryableError, + InstrumentationError, + ConfigurationError +} = require("../../util/errorTypes"); const { executeCommonValidations } = require("../../util/regulation-api"); +const tags = require("../../util/tags"); const userDeletionHandler = async (userAttributes, config) => { if (!config) { - throw new CustomError("Config for deletion not present", 400); + throw new ConfigurationError("Config for deletion not present"); } const { apiKey, apiSecret } = config; if (!apiKey || !apiSecret) { - throw new CustomError("api key/secret for deletion not present", 400); + throw new ConfigurationError("api key/secret for deletion not present"); } for (let i = 0; i < userAttributes.length; i += 1) { const uId = userAttributes[i].userId; if (!uId) { - throw new CustomError("User id for deletion not present", 400); + throw new InstrumentationError("User id for deletion not present"); } const data = { user_ids: [uId], requester: "RudderStack" }; const requestOptions = { @@ -29,17 +37,23 @@ const userDeletionHandler = async (userAttributes, config) => { }; const resp = await httpSend(requestOptions); if (!resp || !resp.response) { - throw new CustomError("Could not get response", 500); + throw new RetryableError("Could not get response"); } if ( resp && resp.response && - resp.response.response && - resp.response.response.status !== 200 // am sends 400 for any bad request or even if user id is not found. The text is also "Bad Request" so not handling user not found case + resp.response?.response && + resp.response?.response?.status !== 200 // am sends 400 for any bad request or even if user id is not found. The text is also "Bad Request" so not handling user not found case ) { - throw new CustomError( - resp.response.response.statusText || "Error while deleting user", - resp.response.response.status + throw new NetworkError( + resp.response?.response?.statusText || "Error while deleting user", + resp.response?.response?.status, + { + [tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType( + resp.response?.response?.status + ) + }, + resp ); } } diff --git a/src/v0/destinations/attentive_tag/util.js b/src/v0/destinations/attentive_tag/util.js index 32bdf75076..d1985bc0e1 100644 --- a/src/v0/destinations/attentive_tag/util.js +++ b/src/v0/destinations/attentive_tag/util.js @@ -2,12 +2,12 @@ const get = require("get-value"); const moment = require("moment"); const { - CustomError, constructPayload, isDefinedAndNotNull, getDestinationExternalID, isDefinedAndNotNullAndNotEmpty } = require("../../util"); +const { InstrumentationError } = require("../../util/errorTypes"); const { mappingConfig, ConfigCategory } = require("./config"); /** @@ -110,9 +110,8 @@ const getDestinationItemProperties = (message, isItemsRequired) => { return items; } if ((!products && isItemsRequired) || (products && products.length === 0)) { - throw new CustomError( - `Products is an required field for '${message.event}' event`, - 400 + throw new InstrumentationError( + `Products is an required field for '${message.event}' event` ); } if (products && Array.isArray(products)) { @@ -132,16 +131,15 @@ const getDestinationItemProperties = (message, isItemsRequired) => { !isDefinedAndNotNull(element.productVariantId) || !isDefinedAndNotNull(pricing.value) ) { - throw new CustomError( - "product_id and product_variant_id and price are required", - 400 + throw new InstrumentationError( + "product_id and product_variant_id and price are required" ); } element.price = price; items.push(element); }); } else if (products && !Array.isArray(products)) { - throw new CustomError("Invalid type. Expected Array of products", 400); + throw new InstrumentationError("Invalid type. Expected Array of products"); } return items; }; From 688657b2cb7b2f2a91103eab11e1f3e46c9f84bf Mon Sep 17 00:00:00 2001 From: ujjwal-ab Date: Wed, 14 Dec 2022 21:16:46 +0530 Subject: [PATCH 8/8] feat: update new error types --- src/cdk/autopilot/transform.js | 15 +++------------ src/v0/destinations/autopilot/transform.js | 15 ++------------- 2 files changed, 5 insertions(+), 25 deletions(-) diff --git a/src/cdk/autopilot/transform.js b/src/cdk/autopilot/transform.js index 4280efedfa..7242204d2f 100644 --- a/src/cdk/autopilot/transform.js +++ b/src/cdk/autopilot/transform.js @@ -1,6 +1,5 @@ const { Utils } = require("rudder-transformer-cdk"); -const ErrorBuilder = require("../../v0/util/error"); -const { TRANSFORMER_METRIC } = require("../../v0/util/constant"); +const { InstrumentationError } = require("../../v0/util/errorTypes"); function identifyPostMapper(event, mappedPayload, rudderContext) { const { message } = event; @@ -51,16 +50,8 @@ function trackPostMapper(event, mappedPayload, rudderContext) { * - if no stat is being set from here, CDK will treat it as an unexpected error occuring in PostMapper * and it shall be treated with priority P0 */ - throw new ErrorBuilder() - .setStatus(400) - .setMessage("Email is required for track calls") - .setStatTags({ - destination: "autopilot", - stage: TRANSFORMER_METRIC.TRANSFORMER_STAGE.TRANSFORM, - scope: TRANSFORMER_METRIC.MEASUREMENT_TYPE.TRANSFORMATION.SCOPE, - meta: TRANSFORMER_METRIC.MEASUREMENT_TYPE.TRANSFORMATION.META.BAD_PARAM - }) - .build(); + throw new InstrumentationError("Email is required for track calls"); + // throw new Error("Email is required for track calls"); } // The plan is to delete the rudderResponse property from the mappedPayload finally diff --git a/src/v0/destinations/autopilot/transform.js b/src/v0/destinations/autopilot/transform.js index c7b65e57c7..91af7256f7 100644 --- a/src/v0/destinations/autopilot/transform.js +++ b/src/v0/destinations/autopilot/transform.js @@ -12,7 +12,7 @@ const { getErrorRespEvents, generateErrorObject } = require("../../util"); -const ErrorBuilder = require("../../util/error"); + const { InstrumentationError, TransformationError @@ -66,18 +66,7 @@ function responseBuilderSimple(message, category, destination) { if (contactIdOrEmail) { response.endpoint = `${category.endPoint}/${destination.Config.triggerId}/contact/${contactIdOrEmail}`; } else { - throw new ErrorBuilder() - .setStatus(400) - .setMessage("Email is required for track calls") - .setStatTags({ - destType: DESTINATION, - stage: TRANSFORMER_METRIC.TRANSFORMER_STAGE.TRANSFORM, - scope: TRANSFORMER_METRIC.MEASUREMENT_TYPE.TRANSFORMATION.SCOPE, - meta: - TRANSFORMER_METRIC.MEASUREMENT_TYPE.TRANSFORMATION.META - .BAD_PARAM - }) - .build(); + throw new InstrumentationError("Email is required for track calls"); // throw new CustomError("Email is required for track calls", 400); } break;