Skip to content

Commit

Permalink
fix: review comments addressed
Browse files Browse the repository at this point in the history
  • Loading branch information
shrouti1507 committed Jan 31, 2024
1 parent 345f903 commit 43f2817
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
25 changes: 15 additions & 10 deletions src/v0/util/facebookUtils/networkHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ const {
NetworkError,
ConfigurationAuthError,
isDefinedAndNotNull,
ERROR_TYPES,
TAG_NAMES,
METADATA,
} = require('@rudderstack/integrations-lib');
const {
processAxiosResponse,
getDynamicErrorType,
} = require('../../../adapters/utils/networkUtils');
const { prepareProxyRequest, proxyRequest } = require('../../../adapters/network');
const tags = require('../tags');
const { ErrorDetailsExtractorBuilder } = require('../../../util/error-extractor');

/**
Expand Down Expand Up @@ -105,24 +107,24 @@ const errorDetailsMap = {
460: new ErrorDetailsExtractorBuilder()
.setStatus(400)
.setStat({
[tags.TAG_NAMES.ERROR_TYPE]: tags.ERROR_TYPES.ACCESS_TOKEN_EXPIRED,
[TAG_NAMES.ERROR_TYPE]: ERROR_TYPES.AUTH,
})
.setMessage(
'The session has been invalidated because the user changed their password or Facebook has changed the session for security reasons',
)
.build(),
463: new ErrorDetailsExtractorBuilder()

463: new ErrorDetailsExtractorBuilder()
.setStatus(400)
.setStat({
[tags.TAG_NAMES.ERROR_TYPE]: tags.ERROR_TYPES.ACCESS_TOKEN_EXPIRED,
[TAG_NAMES.ERROR_TYPE]: ERROR_TYPES.AUTH,
})
.setMessageField('message')
.setMessageField('message')
.build(),
default: new ErrorDetailsExtractorBuilder()
.setStatus(400)
.setStat({
[tags.TAG_NAMES.ERROR_TYPE]: tags.ERROR_TYPES.UNAUTHORIZED,
[TAG_NAMES.ERROR_TYPE]: ERROR_TYPES.AUTH,
})
.setMessage('Invalid OAuth 2.0 access token')
.build(),
Expand Down Expand Up @@ -236,7 +238,7 @@ const getStatus = (error) => {
// Unhandled error response
return {
status: errorStatus,
stats: { [tags.TAG_NAMES.META]: tags.METADATA.UNHANDLED_STATUS_CODE },
stats: { [TAG_NAMES.META]: METADATA.UNHANDLED_STATUS_CODE },
};
}
errorStatus = errorDetail.status;
Expand All @@ -259,15 +261,18 @@ const errorResponseHandler = (destResponse) => {
}
const { error } = response;
const { status, errorMessage, stats: errorStatTags } = getStatus(error);
if (isDefinedAndNotNull(errorStatTags) && errorStatTags?.[tags.TAG_NAMES.ERROR_TYPE] === 'accessTokenExpired') {
if (
isDefinedAndNotNull(errorStatTags) &&
errorStatTags?.[TAG_NAMES.ERROR_TYPE] === 'accessTokenExpired'
) {
throw new ConfigurationAuthError(`${errorMessage}`);
}
throw new NetworkError(
`${errorMessage || error.message || 'Unknown failure during response transformation'}`,
status,
{
...errorStatTags,
[tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(status),
[TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(status),
},
{ ...response, status: destResponse.status },
);
Expand Down
2 changes: 1 addition & 1 deletion src/v0/util/tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const ERROR_TYPES = {
UNSUPPORTED: 'unsupported',
REDIS: 'redis',
FILTERED: 'filtered',
UNAUTHORIZED: 'accessTokenExpired',
AUTH: 'accessTokenExpired',
};

const METADATA = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,8 @@ export const data = [
body: {
output: {
destinationResponse: '',
message: 'Invalid OAuth 2.0 access token',
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.',
statTags: {
destType: 'FB_CUSTOM_AUDIENCE',
destinationId: 'Non-determininable',
Expand Down

0 comments on commit 43f2817

Please sign in to comment.