From 5edd586ae512c133bd92a8f919bf4b9d5978ca63 Mon Sep 17 00:00:00 2001 From: ItsSudip Date: Thu, 29 Feb 2024 07:45:16 +0530 Subject: [PATCH] fix: add error handling for tiktok ads --- src/v0/destinations/tiktok_ads/transform.js | 8 ++-- .../destinations/tiktok_ads/processor/data.ts | 47 ++++++++++++++++++- 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/src/v0/destinations/tiktok_ads/transform.js b/src/v0/destinations/tiktok_ads/transform.js index b8b10d4608..ba852b9a97 100644 --- a/src/v0/destinations/tiktok_ads/transform.js +++ b/src/v0/destinations/tiktok_ads/transform.js @@ -129,12 +129,10 @@ const getTrackResponse = (message, Config, event) => { const trackResponseBuilder = async (message, { Config }) => { const { eventsToStandard, sendCustomEvents } = Config; - - let event = message.event?.toLowerCase().trim(); - if (!event) { - throw new InstrumentationError('Event name is required'); + if (!message.event || typeof message.event !== 'string') { + throw new InstrumentationError('Either event name is not present or it is not a string'); } - + let event = message.event?.toLowerCase().trim(); const standardEventsMap = getHashFromArrayWithDuplicate(eventsToStandard); if (!sendCustomEvents && eventNameMapping[event] === undefined && !standardEventsMap[event]) { diff --git a/test/integrations/destinations/tiktok_ads/processor/data.ts b/test/integrations/destinations/tiktok_ads/processor/data.ts index 3b68426fbf..318d34f82e 100644 --- a/test/integrations/destinations/tiktok_ads/processor/data.ts +++ b/test/integrations/destinations/tiktok_ads/processor/data.ts @@ -1369,7 +1369,7 @@ export const data = [ body: [ { statusCode: 400, - error: 'Event name is required', + error: 'Either event name is not present or it is not a string', statTags: { errorCategory: 'dataValidation', errorType: 'instrumentation', @@ -6973,4 +6973,49 @@ export const data = [ }, }, }, + { + name: 'tiktok_ads', + description: 'Test 8', + feature: 'processor', + module: 'destination', + version: 'v0', + input: { + request: { + body: [ + { + message: { + type: 'track', + event: 123, + }, + destination: { + Config: { + accessToken: 'dummyAccessToken', + pixelCode: '{{PIXEL-CODE}}', + hashUserProperties: false, + }, + }, + }, + ], + }, + }, + output: { + response: { + status: 200, + body: [ + { + statusCode: 400, + error: 'Either event name is not present or it is not a string', + statTags: { + errorCategory: 'dataValidation', + errorType: 'instrumentation', + destType: 'TIKTOK_ADS', + module: 'destination', + implementation: 'native', + feature: 'processor', + }, + }, + ], + }, + }, + }, ];