Skip to content
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: add new stat for access token expired in fb custom audience #3043

Merged
merged 16 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/util/error-extractor/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
/* eslint-disable max-classes-per-file */
import { MessageDetails, StatusCode } from "./types";
import { MessageDetails, StatusCode, Stat } from "./types";

export class ErrorDetailsExtractor {
status: StatusCode;

messageDetails: MessageDetails;

stat : Stat

constructor (builder: ErrorDetailsExtractorBuilder) {
this.status = builder.getStatus();
this.messageDetails = builder.getMessageDetails();
this.stat = builder.getStat();
}

}
Expand All @@ -18,16 +21,23 @@ export class ErrorDetailsExtractorBuilder {

messageDetails: MessageDetails;

stat: Stat;
constructor() {
this.status = 0;
this.messageDetails = {};
this.stat = {};
}

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

setStat(stat: Record<string, string>): ErrorDetailsExtractorBuilder {
this.stat = stat
return this;
}

/**
* This means we need to set a message from a specific field that we see from the destination's response
*
Expand Down Expand Up @@ -69,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
3 changes: 2 additions & 1 deletion src/util/error-extractor/types.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export type MessageDetails = Record<string, string>;
export type StatusCode = number;
export type StatusCode = number;
export type Stat = Record<string, string>
16 changes: 11 additions & 5 deletions src/v0/util/facebookUtils/networkHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,16 @@ const errorDetailsMap = {
190: {
460: new ErrorDetailsExtractorBuilder()
.setStatus(400)
.setStat('accessTokenExpired')
shrouti1507 marked this conversation as resolved.
Show resolved Hide resolved
.setMessage(
'The session has been invalidated because the user changed their password or Facebook has changed the session for security reasons',
)
.build(),
default: new ErrorDetailsExtractorBuilder()
.setStatus(400)
.setStat({
[tags.TAG_NAMES.ERROR_TYPE]: tags.ERROR_TYPES.ACCESS_TOKEN_EXPIRED,
})
shrouti1507 marked this conversation as resolved.
Show resolved Hide resolved
.setMessage('Invalid OAuth 2.0 access token')
.build(),
},
Expand Down Expand Up @@ -211,6 +215,7 @@ const getErrorDetailsFromErrorMap = (error) => {

const getStatus = (error) => {
const errorDetail = getErrorDetailsFromErrorMap(error);
console.log(errorDetail);
let errorStatus = 500;
const isErrorDetailEmpty = isEmpty(errorDetail);
if (isErrorDetailEmpty) {
Expand All @@ -226,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 @@ -241,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
3 changes: 2 additions & 1 deletion src/v0/util/tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const ERROR_CATEGORIES = {
DATA_VALIDATION: 'dataValidation',
NETWORK: 'network',
PLATFORM: 'platform',
TRANSFORMATION: 'transformation',
TRANSFORMATION: 'transformation'
};

const ERROR_TYPES = {
Expand All @@ -52,6 +52,7 @@ const ERROR_TYPES = {
UNSUPPORTED: 'unsupported',
REDIS: 'redis',
FILTERED: 'filtered',
ACCESS_TOKEN_EXPIRED: 'accessTokenExpired'
};

const METADATA = {
Expand Down
Loading
Loading