From 0771e87ff73181c412636f9bde40b8947a3e3080 Mon Sep 17 00:00:00 2001 From: gitcommitshow Date: Tue, 5 Mar 2024 23:48:49 +0530 Subject: [PATCH] fix: handle error-first --- src/v0/sources/slack/transform.js | 33 +++++++++++++++---------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/src/v0/sources/slack/transform.js b/src/v0/sources/slack/transform.js index 12c60df2ba..d67d1bb017 100644 --- a/src/v0/sources/slack/transform.js +++ b/src/v0/sources/slack/transform.js @@ -29,25 +29,24 @@ function processNormalEvent(slackPayload) { break; } message.setEventName(normalizeEventName(slackPayload.event.type)); - if (slackPayload.event.user) { - const stringifiedUserId = - typeof slackPayload.event.user === 'object' - ? slackPayload.event.user.id - : slackPayload.event.user; - message.setProperty( - 'anonymousId', - stringifiedUserId ? sha256(stringifiedUserId).toString().substring(0, 36) : generateUUID(), - ); - // Set the user id received from Slack into externalId - message.context.externalId = [ - { - type: 'slackUserId', - id: stringifiedUserId, - }, - ]; - } else { + if (!slackPayload.event.user) { throw new TransformationError('UserId not found'); } + const stringifiedUserId = + typeof slackPayload.event.user === 'object' + ? slackPayload.event.user.id + : slackPayload.event.user; + message.setProperty( + 'anonymousId', + stringifiedUserId ? sha256(stringifiedUserId).toString().substring(0, 36) : generateUUID(), + ); + // Set the user id received from Slack into externalId + message.context.externalId = [ + { + type: 'slackUserId', + id: stringifiedUserId, + }, + ]; // Set the standard common event fields. More info at https://www.rudderstack.com/docs/event-spec/standard-events/common-fields/ // originalTimestamp - The actual time (in UTC) when the event occurred message.setProperty(