Skip to content

Commit

Permalink
fix: update default handling for some error codes
Browse files Browse the repository at this point in the history
- used error_user_msg field as error message
- when no error is seen, handled error by stringifying
- update test-cases
  • Loading branch information
Sai Sankeerth committed Nov 28, 2024
1 parent bf9ef2a commit f89727a
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 31 deletions.
33 changes: 17 additions & 16 deletions src/v0/util/facebookUtils/networkHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,66 +110,64 @@ const errorDetailsMap = {
.setStat({
[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',
)
.setMessageField('error_user_msg')
.build(),

463: new ErrorDetailsExtractorBuilder()
.setStatus(400)
.setStat({
[TAG_NAMES.ERROR_TYPE]: ERROR_TYPES.AUTH,
})
.setMessageField('message')
.setMessageField('error_user_msg')
.build(),
default: new ErrorDetailsExtractorBuilder()
.setStatus(400)
.setStat({
[TAG_NAMES.ERROR_TYPE]: ERROR_TYPES.AUTH,
})
.setMessage('Invalid OAuth 2.0 access token')
.setMessageField('error_user_msg')
.build(),
},
3: {
default: new ErrorDetailsExtractorBuilder()
.setStatus(400)
.setMessage('Capability or permissions issue.')
.setMessageField('error_user_msg')
.build(),
},
2: {
default: new ErrorDetailsExtractorBuilder()
.setStatus(500)
.setMessage('Temporary issue due to downtime.')
.setMessageField('error_user_msg')
.build(),
},
341: {
default: new ErrorDetailsExtractorBuilder()
.setStatus(500)
.setMessage('Application limit reached: Temporary issue due to downtime or throttling')
.setMessageField('error_user_msg')
.build(),
},
368: {
default: new ErrorDetailsExtractorBuilder()
.setStatus(500)
.setMessage('Temporarily blocked for policies violations.')
.setMessageField('error_user_msg')
.build(),
},
5000: {
default: new ErrorDetailsExtractorBuilder()
.setStatus(500)
.setMessage('Unknown Error Code')
.setMessageField('error_user_msg')
.build(),
},
4: {
default: new ErrorDetailsExtractorBuilder()
.setStatus(429)
.setMessage('API Too Many Calls')
.setMessageField('error_user_msg')
.build(),
},
17: {
default: new ErrorDetailsExtractorBuilder()
.setStatus(429)
.setMessage('API User Too Many Calls')
.setMessageField('error_user_msg')
.build(),
},
// facebook custom audience related error codes
Expand All @@ -179,9 +177,7 @@ const errorDetailsMap = {
294: {
default: new ErrorDetailsExtractorBuilder()
.setStatus(400)
.setMessage(
'Missing permission. Please make sure you have ads_management permission and the application is included in the allowlist',
)
.setMessageField('error_user_msg')
.build(),
},
1487301: {
Expand Down Expand Up @@ -217,7 +213,10 @@ const errorDetailsMap = {
.build(),
},
200: {
default: new ErrorDetailsExtractorBuilder().setStatus(403).setMessageField('message').build(),
default: new ErrorDetailsExtractorBuilder()
.setStatus(403)
.setMessageField('error_user_msg')
.build(),
},
21009: {
default: new ErrorDetailsExtractorBuilder().setStatus(500).setMessageField('message').build(),
Expand All @@ -239,9 +238,11 @@ const getStatus = (error) => {
const isErrorDetailEmpty = isEmpty(errorDetail);
if (isErrorDetailEmpty) {
// Unhandled error response
const errorMessage = get(error?.error || error, 'error_user_msg');
return {
status: errorStatus,
stats: { [TAG_NAMES.META]: METADATA.UNHANDLED_STATUS_CODE },
errorMessage: errorMessage || JSON.stringify(error),
};
}
errorStatus = errorDetail.status;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const testScenariosForV1API: ProxyV1TestData[] = [
body: {
output: {
status: 400,
message: 'Invalid OAuth 2.0 access token',
message: 'The access token could not be decrypted',
statTags: {
...statTags,
errorCategory: 'dataValidation',
Expand All @@ -51,7 +51,7 @@ export const testScenariosForV1API: ProxyV1TestData[] = [
},
response: [
{
error: 'Invalid OAuth 2.0 access token',
error: 'The access token could not be decrypted',
statusCode: 400,
metadata: generateMetadata(1),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,13 @@ export const v0TestData = [
body: {
output: {
status: 400,
message: 'Invalid OAuth 2.0 access token',
message: 'The access token could not be decrypted',
destinationResponse: {
error: {
code: 190,
fbtrace_id: 'fbpixel_trace_id',
message: 'The access token could not be decrypted',
error_user_msg: 'The access token could not be decrypted',
type: 'OAuthException',
},
status: 500,
Expand Down Expand Up @@ -202,7 +203,7 @@ export const v0TestData = [
body: {
output: {
status: 429,
message: 'API User Too Many Calls',
message: 'User request limit reached',
destinationResponse: {
error: {
message: 'User request limit reached',
Expand Down Expand Up @@ -414,7 +415,7 @@ export const v0TestData = [
body: {
output: {
status: 400,
message: 'Capability or permissions issue.',
message: 'Some error in permission',
destinationResponse: {
error: {
message: 'Some error in permission',
Expand Down Expand Up @@ -466,7 +467,8 @@ export const v0TestData = [
body: {
output: {
status: 500,
message: 'Unhandled random error',
message:
'{"message":"Unhandled random error","type":"RandomException","code":5,"error_subcode":12,"fbtrace_id":"facebook_px_trace_id_10"}',
destinationResponse: {
error: {
message: 'Unhandled random error',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ export const oauthScenariosV1: ProxyV1TestData[] = [
body: {
output: {
status: 400,
message: 'Capability or permissions issue.',
message: 'Some error in permission',
statTags,
response: [
{
error: 'Capability or permissions issue.',
error: 'Some error in permission',
statusCode: 400,
metadata: generateMetadata(1),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ export const otherScenariosV1: ProxyV1TestData[] = [
body: {
output: {
status: 429,
message: 'API User Too Many Calls',
message: 'User request limit reached',
statTags: {
...statTags,
errorType: 'throttled',
},
response: [
{
error: 'API User Too Many Calls',
error: 'User request limit reached',
statusCode: 429,
metadata: generateMetadata(1),
},
Expand Down Expand Up @@ -72,15 +72,17 @@ export const otherScenariosV1: ProxyV1TestData[] = [
body: {
output: {
status: 500,
message: 'Unhandled random error',
message:
'{"message":"Unhandled random error","type":"RandomException","code":5,"error_subcode":12,"fbtrace_id":"facebook_px_trace_id_10"}',
statTags: {
...statTags,
errorType: 'retryable',
meta: 'unhandledStatusCode',
},
response: [
{
error: 'Unhandled random error',
error:
'{"message":"Unhandled random error","type":"RandomException","code":5,"error_subcode":12,"fbtrace_id":"facebook_px_trace_id_10"}',
statusCode: 500,
metadata: generateMetadata(1),
},
Expand Down
1 change: 1 addition & 0 deletions test/integrations/destinations/facebook_pixel/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const networkCallsData = [
data: {
error: {
message: 'The access token could not be decrypted',
error_user_msg: 'The access token could not be decrypted',
type: 'OAuthException',
code: 190,
fbtrace_id: 'fbpixel_trace_id',
Expand Down
3 changes: 2 additions & 1 deletion test/integrations/destinations/fb/dataDelivery/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export const existingTestData = [
message: 'Invalid OAuth 2.0 access token',
destinationResponse: {
error: {
error_user_msg: 'Invalid OAuth 2.0 access token',
code: 190,
fbtrace_id: 'fbpixel_trace_id',
message: 'The access token could not be decrypted',
Expand Down Expand Up @@ -274,7 +275,7 @@ export const existingTestData = [
body: {
output: {
status: 429,
message: 'API User Too Many Calls',
message: 'User request limit reached',
destinationResponse: {
error: {
message: 'User request limit reached',
Expand Down
4 changes: 2 additions & 2 deletions test/integrations/destinations/fb/dataDelivery/other.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ export const otherScenariosV1: ProxyV1TestData[] = [
body: {
output: {
status: 429,
message: 'API User Too Many Calls',
message: 'User request limit reached',
statTags: {
...statTags,
errorType: 'throttled',
},
response: [
{
error: 'API User Too Many Calls',
error: 'User request limit reached',
statusCode: 429,
metadata: generateMetadata(1),
},
Expand Down
1 change: 1 addition & 0 deletions test/integrations/destinations/fb/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const networkCallsData = [
data: {
error: {
message: 'The access token could not be decrypted',
error_user_msg: 'Invalid OAuth 2.0 access token',
type: 'OAuthException',
code: 190,
fbtrace_id: 'fbpixel_trace_id',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,8 @@ export const existingTestData = [
fbtrace_id: 'A3b8C6PpI-kdIOwPwV4PANi',
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.',
error_user_msg:
'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',
},
status: 400,
Expand Down
2 changes: 2 additions & 0 deletions test/integrations/destinations/fb_custom_audience/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,8 @@ export const networkCallsData = [
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.',
error_user_msg:
'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,
Expand Down

0 comments on commit f89727a

Please sign in to comment.