Skip to content

Commit

Permalink
fix: initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
shrouti1507 committed Jan 30, 2024
1 parent 0c44eba commit bf328dc
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 84 deletions.
11 changes: 9 additions & 2 deletions src/util/error-extractor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

}
Expand All @@ -22,15 +25,15 @@ export class ErrorDetailsExtractorBuilder {
constructor() {
this.status = 0;
this.messageDetails = {};
this.stat = '';
this.stat = {};
}

setStatus(status: number): ErrorDetailsExtractorBuilder {
this.status = status;
return this;
}

setStat(stat: string): ErrorDetailsExtractorBuilder {
setStat(stat: Record<string, string>): ErrorDetailsExtractorBuilder {
this.stat = stat
return this;
}
Expand Down Expand Up @@ -76,6 +79,10 @@ export class ErrorDetailsExtractorBuilder {
getStatus(): number {
return this.status;
}

getStat(): Record<string, string> {
return this.stat;
}

getMessageDetails(): Record<string, string> {
return this.messageDetails;
Expand Down
2 changes: 1 addition & 1 deletion src/util/error-extractor/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export type MessageDetails = Record<string, string>;
export type StatusCode = number;
export type Stat = string;
export type Stat = Record<string, string>
15 changes: 9 additions & 6 deletions src/v0/util/facebookUtils/networkHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
},
Expand Down Expand Up @@ -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) => {
Expand All @@ -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 },
);
};
Expand Down
4 changes: 2 additions & 2 deletions src/v0/util/tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -53,6 +52,7 @@ const ERROR_TYPES = {
UNSUPPORTED: 'unsupported',
REDIS: 'redis',
FILTERED: 'filtered',
ACCESS_TOKEN_EXPIRED: 'accessTokenExpired'
};

const METADATA = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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: {
Expand All @@ -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"
}
}
},
},
}
},
];
38 changes: 6 additions & 32 deletions test/integrations/destinations/fb_custom_audience/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
[
'[email protected]',
'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: '',
Expand Down

0 comments on commit bf328dc

Please sign in to comment.