diff --git a/src/v0/util/constant.js b/src/v0/util/constant.js index be576d4520..8fd284b04b 100644 --- a/src/v0/util/constant.js +++ b/src/v0/util/constant.js @@ -8,74 +8,8 @@ const AUTH_CACHE_TTL = process.env.MARKETO_AUTH_CACHE_TTL const API_CALL = "api_call_count"; -const TRANSFORMER_METRIC = { - MEASUREMENT: { - INTEGRATION_ERROR_METRIC: "integration_error_metric" - }, - // The location at which the error stat was sent - ERROR_AT: { - // processor transformation - PROC: "proc", - // router transformation - RT: "rt", - // batch transformation - BATCH: "batch", - // /proxy endpoint(delivery to destination) - PROXY: "proxy", - // Default - UNKNOWN: "unknown" - }, - TRANSFORMER_STAGE: { - TRANSFORM: "transform", - RESPONSE_TRANSFORM: "responseTransform" - }, - MEASUREMENT_TYPE: { - API: { - SCOPE: "api", - META: { - ABORTABLE: "abortable", - RETRYABLE: "retryable", - THROTTLED: "throttled", - SUCCESS: "success", - /** - * This meta needs to be used when the response is not an expected one from the destination's API - * This can be during transformation or response handling(during delivery of event) - */ - UNHANDLED: "unhandled" - } - }, - TRANSFORMATION: { - SCOPE: "transformation", - META: { - BAD_EVENT: "badEvent", - BAD_PARAM: "badParam", - INSTRUMENTATION: "instrumentation", - CONFIGURATION: "configuration", - /** - * Basically this means that the error is an expected error(thrown during transformation) - * This meta will be used for CustomError thrown during transformations - */ - HANDLED: "handled" - } - }, - AUTHENTICATION: { - SCOPE: "authentication" - }, - EXCEPTION: { - SCOPE: "exception" - }, - CDK: { - SCOPE: "cdk" - }, - DEFAULT: { - SCOPE: "default" - } - } -}; - module.exports = { API_CALL, AUTH_CACHE_TTL, - TRANSFORMER_METRIC, USER_LEAD_CACHE_TTL }; diff --git a/src/v0/util/error.js b/src/v0/util/error.js deleted file mode 100644 index 5e063f86b2..0000000000 --- a/src/v0/util/error.js +++ /dev/null @@ -1,107 +0,0 @@ -// Todo add documentation for internal functions -function ErrorBuilder() { - this.err = new Error(); - this.err.isExpected = true; - - /** - * sets the error message for thrown error - * @param {*} message - * @returns - */ - this.setMessage = message => { - this.err.message = message; - return this; - }; - - /** - * sets the status-code which has to be processed by server - * @param {*} status - * @returns - */ - this.setStatus = status => { - this.err.status = status; - return this; - }; - - /** - * sets the raw response from the external API calls(if any) - * @param {*} destinationResponse - * @returns - */ - this.setDestinationResponse = destinationResponse => { - this.err.destinationResponse = destinationResponse; - return this; - }; - - this.isTransformResponseFailure = arg => { - this.err.responseTransformFailure = arg; - return this; - }; - - this.setStatTags = arg => { - this.err.statTags = { - destType: arg.destType || arg.destination, - stage: arg.stage, - scope: arg.scope, - meta: arg.meta - }; - return this; - }; - - // Used for only OAuth related destinations - this.setAuthErrorCategory = errorCat => { - this.err.authErrorCategory = errorCat; - return this; - }; - - /** - * The below mentioned methods have been provided - * as we would need to set some defaults for errors to be thrown at each destination level - * These would be apt for that sort of scenario - * - * For Example - * algolia/transform.js - * // We would initialise the error - * // Note: We would be using constants to set meta - * throw new ErrorBuilder().setDestType("ALGOLIA").setStage("transform").setMeta("badParam").build(); - * - * This way things would easier to handle at destination level - */ - - this.setDestType = destType => { - destType = destType?.toUpperCase(); - this.err.statTags = { - ...this.err.statTags, - destType - }; - return this; - }; - - this.setStage = stage => { - this.err.statTags = { - ...this.err.statTags, - stage - }; - return this; - }; - - this.setScope = scope => { - this.err.statTags = { - ...this.err.statTags, - scope - }; - return this; - }; - - this.setMeta = meta => { - this.err.statTags = { - ...this.err.statTags, - meta - }; - return this; - }; - - this.build = () => this.err; -} - -module.exports = ErrorBuilder; diff --git a/src/v0/util/errors/api.js b/src/v0/util/errors/api.js deleted file mode 100644 index 72cd8f1875..0000000000 --- a/src/v0/util/errors/api.js +++ /dev/null @@ -1,25 +0,0 @@ -const { TRANSFORMER_METRIC } = require("../constant"); -const { RudderErrorBase } = require("./base"); - -class ApiError extends RudderErrorBase { - constructor( - message, - statusCode = 400, - statTags, - destResponse, - authErrCategory = "", - destination - ) { - const defScope = TRANSFORMER_METRIC.MEASUREMENT_TYPE.API.SCOPE; - const defMeta = TRANSFORMER_METRIC.MEASUREMENT_TYPE.API.META.UNHANDLED; - const finalStatTags = RudderErrorBase.populateStatTags(statTags, { - meta: defMeta, - scope: defScope, - destType: destination - }); - - super(message, statusCode, finalStatTags, destResponse, authErrCategory); - } -} - -module.exports = ApiError; diff --git a/src/v0/util/errors/base.js b/src/v0/util/errors/base.js deleted file mode 100644 index d9c927627d..0000000000 --- a/src/v0/util/errors/base.js +++ /dev/null @@ -1,27 +0,0 @@ -class BaseError extends Error { - constructor( - message = "", - statusCode = 400, - sTags = {}, - destResponse = "", - authErrCategory = "" - ) { - super(message); - this.status = statusCode; - this.statTags = sTags; - this.destinationResponse = destResponse; - this.authErrorCategory = authErrCategory; - } - - static populateStatTags(statTags, defaults) { - return { - destType: - statTags?.destType || statTags?.destination || defaults?.destType, - stage: statTags?.stage || defaults?.stage, - scope: statTags?.scope || defaults?.scope, - meta: statTags?.meta || defaults?.meta - }; - } -} - -module.exports = { BaseError }; diff --git a/src/v0/util/errors/index.js b/src/v0/util/errors/index.js deleted file mode 100644 index 27c789eec1..0000000000 --- a/src/v0/util/errors/index.js +++ /dev/null @@ -1,9 +0,0 @@ -const { RudderErrorBase } = require("./base"); -const TransformationError = require("./transformation"); -const ApiError = require("./api"); - -module.exports = { - TransformationError, - ApiError, - RudderErrorBase -}; diff --git a/src/v0/util/errors/transformation.js b/src/v0/util/errors/transformation.js deleted file mode 100644 index 26f1ecbeba..0000000000 --- a/src/v0/util/errors/transformation.js +++ /dev/null @@ -1,20 +0,0 @@ -const { TRANSFORMER_METRIC } = require("../constant"); -const { RudderErrorBase } = require("./base"); - -class TransformationError extends RudderErrorBase { - constructor(message, statusCode = 400, statTags, destination) { - const defScope = TRANSFORMER_METRIC.MEASUREMENT_TYPE.TRANSFORMATION.SCOPE; - const defMeta = - TRANSFORMER_METRIC.MEASUREMENT_TYPE.TRANSFORMATION.META.HANDLED; - - const finalStatTags = RudderErrorBase.populateStatTags(statTags, { - meta: defMeta, - scope: defScope, - destType: destination - }); - - super(message, statusCode, finalStatTags); - } -} - -module.exports = TransformationError; diff --git a/src/v0/util/index.js b/src/v0/util/index.js index 0665a70914..390ca5e894 100644 --- a/src/v0/util/index.js +++ b/src/v0/util/index.js @@ -45,15 +45,6 @@ const flattenMap = collection => _.flatMap(collection, x => x); // GENERIC UTLITY // ======================================================================== -class CustomError extends Error { - constructor(message, statusCode, metadata) { - super(message); - // *Note*: This schema is being used by other endpoints like /poll, /fileUpload etc,. - // Apart from destination transformation - this.response = { status: statusCode || 400, metadata }; - } -} - const getEventTime = message => { return new Date(message.timestamp).toISOString(); };