-
Notifications
You must be signed in to change notification settings - Fork 105
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 (snapchat_custom_audience, snapchat_conversion, slack, singular, signl4) #1655
Changes from 2 commits
9e3c3ff
b6eb156
4455c89
cfc4471
fb093e7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -3,24 +3,21 @@ const { | |||||
defaultRequestConfig, | ||||||
defaultGetRequestConfig, | ||||||
getSuccessRespEvents, | ||||||
getErrorRespEvents, | ||||||
CustomError | ||||||
getErrorRespEvents | ||||||
} = require("../../util"); | ||||||
|
||||||
const { | ||||||
platformWisePayloadGenerator, | ||||||
generateRevenuePayloadArray, | ||||||
isSessionEvent | ||||||
} = require("./util"); | ||||||
const { InstrumentationError } = require("../../util/errorTypes"); | ||||||
|
||||||
const responseBuilderSimple = (message, { Config }) => { | ||||||
const eventName = message.event; | ||||||
|
||||||
if (!eventName) { | ||||||
throw new CustomError( | ||||||
"[Singular]::event name is not present for the event", | ||||||
400 | ||||||
); | ||||||
throw new InstrumentationError("event name is not present for the event"); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
|
||||||
const sessionEvent = isSessionEvent(Config, eventName); | ||||||
|
@@ -58,18 +55,15 @@ const responseBuilderSimple = (message, { Config }) => { | |||||
|
||||||
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(); | ||||||
|
||||||
if (messageType === "track") { | ||||||
return responseBuilderSimple(message, destination); | ||||||
} | ||||||
|
||||||
throw new CustomError("[Singular]: Message type not supported", 400); | ||||||
throw new InstrumentationError(`Event type ${messageType} is not supported`); | ||||||
}; | ||||||
|
||||||
const process = event => { | ||||||
|
@@ -102,11 +96,7 @@ const processRouterDest = inputs => { | |||||
} catch (error) { | ||||||
return getErrorRespEvents( | ||||||
[input.metadata], | ||||||
error.response | ||||||
? error.response.status | ||||||
: error.code | ||||||
? error.code | ||||||
: 400, | ||||||
error.response ? error.response.status : error.code || 400, | ||||||
error.message || "Error occurred while processing payload." | ||||||
); | ||||||
} | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -15,12 +15,15 @@ const { | |||||
defaultRequestConfig, | ||||||
defaultGetRequestConfig, | ||||||
removeUndefinedAndNullValues, | ||||||
CustomError, | ||||||
extractCustomFields, | ||||||
getValueFromMessage, | ||||||
isDefinedAndNotNull, | ||||||
isAppleFamily | ||||||
} = require("../../util"); | ||||||
const { | ||||||
TransformationError, | ||||||
InstrumentationError | ||||||
} = require("../../util/errorTypes"); | ||||||
|
||||||
/* | ||||||
All the fields listed inside properties which are not directly mapped, will be sent to 'e' as custom event attributes | ||||||
|
@@ -106,7 +109,7 @@ const platformWisePayloadGenerator = (message, isSessionEvent) => { | |||||
let platform = getValueFromMessage(message, "context.os.name"); | ||||||
const typeOfEvent = isSessionEvent ? "SESSION" : "EVENT"; | ||||||
if (!platform) { | ||||||
throw new CustomError("[Singular] :: Platform name is missing", 400); | ||||||
throw new InstrumentationError("Platform name is missing"); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
// checking if the os is one of ios, ipados, watchos, tvos | ||||||
if (typeof platform === "string" && isAppleFamily(platform.toLowerCase())) { | ||||||
|
@@ -115,7 +118,7 @@ const platformWisePayloadGenerator = (message, isSessionEvent) => { | |||||
} | ||||||
platform = platform.toLowerCase(); | ||||||
if (!SUPPORTED_PLATFORM[platform]) { | ||||||
throw new CustomError("[Singular] :: Platform is not supported"); | ||||||
throw new InstrumentationError("Platform is not supported"); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
|
||||||
const payload = constructPayload( | ||||||
|
@@ -126,9 +129,8 @@ const platformWisePayloadGenerator = (message, isSessionEvent) => { | |||||
); | ||||||
|
||||||
if (!payload) { | ||||||
throw new CustomError( | ||||||
`Failed to Create ${platform} ${typeOfEvent} Payload`, | ||||||
400 | ||||||
throw new TransformationError( | ||||||
`Failed to Create ${platform} ${typeOfEvent} Payload` | ||||||
); | ||||||
} | ||||||
if (isSessionEvent) { | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,6 @@ const { | |
removeUndefinedAndNullValues, | ||
getFieldValueFromMessage, | ||
getSuccessRespEvents, | ||
CustomError, | ||
isAppleFamily, | ||
getValidDynamicFormConfig, | ||
checkInvalidRtTfEvents, | ||
|
@@ -33,6 +32,7 @@ const { | |
channelMapping, | ||
generateBatchedPayloadForArray | ||
} = require("./util"); | ||
const { InstrumentationError } = require("../../util/errorTypes"); | ||
|
||
// Returns the response for the track event after constructing the payload and setting necessary fields | ||
function trackResponseBuilder(message, { Config }, mappedEvent) { | ||
|
@@ -57,23 +57,16 @@ function trackResponseBuilder(message, { Config }, mappedEvent) { | |
(eventConversionType === "WEB" || eventConversionType === "OFFLINE") && | ||
!pixelId | ||
) { | ||
throw new CustomError( | ||
"[Snapchat] :: Pixel Id is required for web and offline events", | ||
400 | ||
throw new InstrumentationError( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be |
||
"Pixel Id is required for web and offline events" | ||
); | ||
} | ||
|
||
if (eventConversionType === "MOBILE_APP" && !(appId && snapAppId)) { | ||
if (!appId) { | ||
throw new CustomError( | ||
"[Snapchat] :: App Id is required for app events", | ||
400 | ||
); | ||
throw new InstrumentationError("App Id is required for app events"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} else { | ||
throw new CustomError( | ||
"[Snapchat] :: Snap App Id is required for app events", | ||
400 | ||
); | ||
throw new InstrumentationError("Snap App Id is required for app events"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||
} | ||
} | ||
|
||
|
@@ -178,9 +171,8 @@ function trackResponseBuilder(message, { Config }, mappedEvent) { | |
break; | ||
} | ||
} else { | ||
throw new CustomError( | ||
`Event ${event} doesn't match with Snapchat Events!`, | ||
400 | ||
throw new InstrumentationError( | ||
`Event ${event} doesn't match with Snapchat Events!` | ||
); | ||
} | ||
|
||
|
@@ -239,9 +231,8 @@ function trackResponseBuilder(message, { Config }, mappedEvent) { | |
!payload.hashed_mobile_ad_id && | ||
!(payload.hashed_ip_address && payload.user_agent) | ||
) { | ||
throw new CustomError( | ||
"At least one of email or phone or advertisingId or ip and userAgent is required", | ||
400 | ||
throw new InstrumentationError( | ||
"At least one of email or phone or advertisingId or ip and userAgent is required" | ||
); | ||
} | ||
payload.timestamp = getFieldValueFromMessage(message, "timestamp"); | ||
|
@@ -252,9 +243,8 @@ function trackResponseBuilder(message, { Config }, mappedEvent) { | |
// calculates past event in days | ||
const deltaDay = Math.ceil(moment.duration(current.diff(start)).asDays()); | ||
if (deltaDay > 28) { | ||
throw new CustomError( | ||
"[snapchat_conversion]: Events must be sent within 28 days of their occurrence.", | ||
400 | ||
throw new InstrumentationError( | ||
"Events must be sent within 28 days of their occurrence" | ||
); | ||
} | ||
} | ||
|
@@ -302,7 +292,7 @@ function eventMappingHandler(message, destination) { | |
let event = get(message, "event"); | ||
|
||
if (!event) { | ||
throw new CustomError("[Snapchat] :: Event name is required", 400); | ||
throw new InstrumentationError("Event name is required"); | ||
} | ||
event = event.trim().replace(/\s+/g, "_"); | ||
|
||
|
@@ -336,10 +326,7 @@ function process(event) { | |
const { message, destination } = event; | ||
|
||
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(); | ||
|
@@ -363,7 +350,9 @@ function process(event) { | |
break; | ||
} | ||
default: | ||
throw new CustomError(`Message type ${messageType} not supported`, 400); | ||
throw new InstrumentationError( | ||
`Event type ${messageType} is not supported` | ||
); | ||
} | ||
return response; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,12 @@ const { | |
defaultRequestConfig, | ||
removeUndefinedAndNullValues, | ||
simpleProcessRouterDest, | ||
CustomError, | ||
isDefinedAndNotNullAndNotEmpty | ||
} = require("../../util"); | ||
const ErrorBuilder = require("../../util/error"); | ||
const { | ||
InstrumentationError, | ||
InvalidAuthTokenError | ||
} = require("../../util/errorTypes"); | ||
const { BASE_URL, schemaType } = require("./config"); | ||
const { validatePayload, validateFields } = require("./utils"); | ||
|
||
|
@@ -26,10 +28,7 @@ const getAccessToken = metadata => { | |
const { secret } = metadata; | ||
// we would need to verify if secret is present and also if the access token field is present in secret | ||
if (!secret || !secret.access_token) { | ||
throw new ErrorBuilder() | ||
.setStatus(500) | ||
.setMessage("Empty/Invalid access token") | ||
.build(); | ||
throw new InvalidAuthTokenError("Empty/Invalid access token"); | ||
} | ||
return secret.access_token; | ||
}; | ||
|
@@ -80,7 +79,7 @@ const getProperty = (schema, element) => { | |
element?.MOBILE_ID; | ||
return property; | ||
default: | ||
throw new CustomError("Invalid schema", 400); | ||
throw new InstrumentationError("Invalid schema"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Config error |
||
} | ||
}; | ||
|
||
|
@@ -100,7 +99,7 @@ const getHashedProperty = (schema, hashedProperty) => { | |
case "mobileAdId": | ||
return sha256(hashedProperty.toLowerCase()); | ||
default: | ||
throw new CustomError("Invalid schema", 400); | ||
throw new InstrumentationError("Invalid schema"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Config error |
||
} | ||
}; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.