From bf328dcbe5051dcace42e36f7a3996250433fc24 Mon Sep 17 00:00:00 2001 From: shrouti1507 Date: Tue, 30 Jan 2024 14:02:05 +0530 Subject: [PATCH] fix: initial commit --- src/util/error-extractor/index.ts | 11 ++- src/util/error-extractor/types.ts | 2 +- src/v0/util/facebookUtils/networkHandler.js | 15 ++-- src/v0/util/tags.js | 4 +- .../fb_custom_audience/dataDelivery/data.ts | 77 +++++++++---------- .../fb_custom_audience/network.ts | 38 ++------- 6 files changed, 63 insertions(+), 84 deletions(-) diff --git a/src/util/error-extractor/index.ts b/src/util/error-extractor/index.ts index d4d4a6abc35..68ebac9aca7 100644 --- a/src/util/error-extractor/index.ts +++ b/src/util/error-extractor/index.ts @@ -6,9 +6,12 @@ export class ErrorDetailsExtractor { messageDetails: MessageDetails; + stat : Stat + constructor (builder: ErrorDetailsExtractorBuilder) { this.status = builder.getStatus(); this.messageDetails = builder.getMessageDetails(); + this.stat = builder.getStat(); } } @@ -22,7 +25,7 @@ export class ErrorDetailsExtractorBuilder { constructor() { this.status = 0; this.messageDetails = {}; - this.stat = ''; + this.stat = {}; } setStatus(status: number): ErrorDetailsExtractorBuilder { @@ -30,7 +33,7 @@ export class ErrorDetailsExtractorBuilder { return this; } - setStat(stat: string): ErrorDetailsExtractorBuilder { + setStat(stat: Record): ErrorDetailsExtractorBuilder { this.stat = stat return this; } @@ -76,6 +79,10 @@ export class ErrorDetailsExtractorBuilder { getStatus(): number { return this.status; } + + getStat(): Record { + return this.stat; + } getMessageDetails(): Record { return this.messageDetails; diff --git a/src/util/error-extractor/types.ts b/src/util/error-extractor/types.ts index 33cb14b6900..ff7290b4ff6 100644 --- a/src/util/error-extractor/types.ts +++ b/src/util/error-extractor/types.ts @@ -1,3 +1,3 @@ export type MessageDetails = Record; export type StatusCode = number; -export type Stat = string; \ No newline at end of file +export type Stat = Record \ No newline at end of file diff --git a/src/v0/util/facebookUtils/networkHandler.js b/src/v0/util/facebookUtils/networkHandler.js index a0b420008ff..df9c48e51b5 100644 --- a/src/v0/util/facebookUtils/networkHandler.js +++ b/src/v0/util/facebookUtils/networkHandler.js @@ -107,7 +107,9 @@ const errorDetailsMap = { .build(), default: new ErrorDetailsExtractorBuilder() .setStatus(400) - .setStat('accessTokenExpired') + .setStat({ + [tags.TAG_NAMES.ERROR_TYPE]: tags.ERROR_TYPES.ACCESS_TOKEN_EXPIRED, + }) .setMessage('Invalid OAuth 2.0 access token') .build(), }, @@ -229,8 +231,10 @@ const getStatus = (error) => { if (errorDetail?.messageDetails?.field) { errorMessage = get(error, errorDetail?.messageDetails?.field); } + + let tags = errorDetail?.stat; - return { status: errorStatus, errorMessage }; + return { status: errorStatus, errorMessage, tags }; }; const errorResponseHandler = (destResponse) => { @@ -244,10 +248,9 @@ const errorResponseHandler = (destResponse) => { throw new NetworkError( `${errorMessage || error.message || 'Unknown failure during response transformation'}`, status, - { - ...errorStatTags, - [tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(status), - }, + + // [tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(status), + errorStatTags , { ...response, status: destResponse.status }, ); }; diff --git a/src/v0/util/tags.js b/src/v0/util/tags.js index f2fa92c295d..471f77e939a 100644 --- a/src/v0/util/tags.js +++ b/src/v0/util/tags.js @@ -39,8 +39,7 @@ const ERROR_CATEGORIES = { DATA_VALIDATION: 'dataValidation', NETWORK: 'network', PLATFORM: 'platform', - TRANSFORMATION: 'transformation', - ACCESS_TOKEN_EXPIRED: 'accessTokenExpired' + TRANSFORMATION: 'transformation' }; const ERROR_TYPES = { @@ -53,6 +52,7 @@ const ERROR_TYPES = { UNSUPPORTED: 'unsupported', REDIS: 'redis', FILTERED: 'filtered', + ACCESS_TOKEN_EXPIRED: 'accessTokenExpired' }; const METADATA = { diff --git a/test/integrations/destinations/fb_custom_audience/dataDelivery/data.ts b/test/integrations/destinations/fb_custom_audience/dataDelivery/data.ts index 20872cfb497..1c291823933 100644 --- a/test/integrations/destinations/fb_custom_audience/dataDelivery/data.ts +++ b/test/integrations/destinations/fb_custom_audience/dataDelivery/data.ts @@ -574,7 +574,7 @@ export const data = [ // }, { name: 'fb_custom_audience', - description: 'user addition failed due to missing permission', + description: 'user addition failed due to unavailable audience error', feature: 'dataDelivery', module: 'destination', version: 'v0', @@ -583,33 +583,20 @@ export const data = [ body: { version: '1', type: 'REST', - method: 'POST', - endpoint: getEndPoint('aud10'), + method: 'DELETE', + endpoint: getEndPoint('aud1'), headers: { - 'test-dest-response-key': 'code400accesstokenexpirederror', + 'test-dest-response-key': 'accessTokenInvalidError', }, params: { - access_token: 'ABCD', + access_token: 'ABC', payload: { is_raw: true, data_source: { sub_type: 'ANYTHING', }, - schema: [ - 'DOBM', - 'DOBD', - 'DOBY', - 'PHONE', - 'GEN', - 'FI', - 'MADID', - 'ZIP', - 'ST', - 'COUNTRY', - ], - data: [ - ['2', '13', '2013', '@09432457768', 'f', 'Ms.', 'ABC', 'ZIP ', '123abc ', 'IN'], - ], + schema: ['DOBY', 'PHONE', 'GEN', 'FI', 'MADID', 'ZIP', 'ST', 'COUNTRY'], + data: [['2013', '@09432457768', 'f', 'Ms.', 'ABC', 'ZIP ', '123abc ', 'IN']], }, }, body: { @@ -623,28 +610,36 @@ export const data = [ }, }, output: { - "response": { - "status": 400, - "message": "Invalid OAuth 2.0 access token", - "destinationResponse": { - "error": { - "message": "Error validating access token: Session has expired on Tuesday, 01-Aug-23 10:12:14 PDT. The current time is Sunday, 28-Jan-24 16:01:17 PST.", - "type": "OAuthException", - "code": 190, - "error_subcode": 463, - "fbtrace_id": "A3b8C6PpI-kdIOwPwV4PANi" + response: { + status: 400, + body: { + output: { + destinationResponse: { + error: { + message: 'Error validating access token: Session has expired on Tuesday, 01-Aug-23 10:12:14 PDT. The current time is Sunday, 28-Jan-24 16:01:17 PST.', + type: 'OAuthException', + code: 190, + error_subcode: 463, + fbtrace_id: 'A3b8C6PpI-kdIOwPwV4PANi' + }, + status: 400, + }, + message: + 'Invalid OAuth 2.0 access token', + statTags: { + destType: 'FB_CUSTOM_AUDIENCE', + destinationId: 'Non-determininable', + errorCategory: 'network', + errorType: 'accessTokenExpired', + feature: 'dataDelivery', + implementation: 'native', + module: 'destination', + workspaceId: 'Non-determininable', + }, + status: 400, }, - "status": 400 }, - "statTags": { - "errorCategory": "network", - "errorType": "aborted", - "destType": "FB_CUSTOM_AUDIENCE", - "module": "destination", - "implementation": "native", - "feature": "dataDelivery" - } - } + }, }, - } + }, ]; diff --git a/test/integrations/destinations/fb_custom_audience/network.ts b/test/integrations/destinations/fb_custom_audience/network.ts index f575cb46dea..fa11f28370c 100644 --- a/test/integrations/destinations/fb_custom_audience/network.ts +++ b/test/integrations/destinations/fb_custom_audience/network.ts @@ -484,46 +484,20 @@ export const networkCallsData = [ httpReq: { version: '1', type: 'REST', - method: 'ADD', - endpoint: getEndPoint('aud10'), + method: 'DELETE', + endpoint: getEndPoint('aud1'), headers: { - 'test-dest-response-key': 'code400accesstokenexpirederror', + 'test-dest-response-key': 'accessTokenInvalidError', }, params: { - access_token: 'ABCD', + access_token: 'ABC', payload: { is_raw: true, data_source: { sub_type: 'ANYTHING', }, - schema: [ - 'EMAIL', - 'DOBM', - 'DOBD', - 'DOBY', - 'PHONE', - 'GEN', - 'FI', - 'MADID', - 'ZIP', - 'ST', - 'COUNTRY', - ], - data: [ - [ - 'shrouti@abc.com', - '2', - '13', - '2013', - '@09432457768', - 'f', - 'Ms.', - 'ABC', - 'ZIP ', - '123abc ', - 'IN', - ], - ], + schema: ['DOBY', 'PHONE', 'GEN', 'FI', 'MADID', 'ZIP', 'ST', 'COUNTRY'], + data: [['2013', '@09432457768', 'f', 'Ms.', 'ABC', 'ZIP ', '123abc ', 'IN']], }, }, userId: '',