Repository navigation
fix: handle fb_custom_audience auth error - #4237
Conversation
Summary by CodeRabbit
WalkthroughThis update refines the error handling logic within the Changes
Sequence Diagram(s)sequenceDiagram
participant C as Client
participant EH as ErrorResponseHandler
C->>EH: Receives network response with error details
Note over EH: Validate errorMessage is provided
alt errorMessage exists
EH->>C: Throw error using provided errorMessage
else errorMessage is falsy
EH->>EH: Retrieve error message from error object or use default
alt error code is 190 (auth error)
EH->>C: Throw ConfigurationAuthError with detailed message
else
EH->>C: Throw NetworkError with detailed message
end
end
Suggestions for Improvement
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/v0/util/facebookUtils/networkHandler.test.js (1)
222-241: Duplicate test for rate limiting.This test is similar to the previous rate limit test and validates the same behavior with a different error code. Consider consolidating these tests or using parameterized tests if your testing framework supports it.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (2)
test/integrations/destinations/fb_custom_audience/dataDelivery/data.tsis excluded by!**/test/**test/integrations/destinations/fb_custom_audience/network.tsis excluded by!**/test/**
📒 Files selected for processing (2)
src/v0/util/facebookUtils/networkHandler.js(1 hunks)src/v0/util/facebookUtils/networkHandler.test.js(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.js`: Focus on ESLint errors (max 3) and warnings (max 5).
**/*.js: Focus on ESLint errors (max 3) and warnings (max 5).
src/v0/util/facebookUtils/networkHandler.jssrc/v0/util/facebookUtils/networkHandler.test.js
🧬 Code Definitions (1)
src/v0/util/facebookUtils/networkHandler.js (1)
src/v0/util/index.js (1)
isDefinedAndNotNull(49-49)
⏰ Context from checks skipped due to timeout of 90000ms (8)
- GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image AMD64
- GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image AMD64
- GitHub Check: Code Coverage
- GitHub Check: test_and_publish
- GitHub Check: ingestion-service-test
- GitHub Check: UT Tests
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: Analyze (go)
🔇 Additional comments (14)
src/v0/util/facebookUtils/networkHandler.js (3)
272-275: Good addition of clarifying comments.The comment clearly explains the intent behind the subsequent code changes, helping other developers understand why this check is needed to avoid using a generic base error message.
279-282: Improved error message handling.This change effectively handles the Facebook OAuth expiration errors by providing a proper fallback mechanism when the errorMessage is falsy. It will now use the error.message field which contains important details about token expiration (as seen in the test).
284-286: Similar improvement for NetworkError handling.The same fallback pattern is consistently applied here, which is good for code uniformity. This ensures meaningful error messages are provided regardless of the error type.
src/v0/util/facebookUtils/networkHandler.test.js (11)
1-14: Good test setup for successful responses.The test file starts with the appropriate imports and a basic test to verify no errors are thrown when the response is successful, establishing a baseline for further tests.
16-36: Appropriate test for basic AUTH error handling.This test verifies that ConfigurationAuthError is thrown with the correct message and status code when an OAuth error occurs with error_user_msg present.
38-58: Good test for NetworkError with appropriate error details.The test validates that NetworkError is thrown with the correct message from error_user_title when specific error codes are encountered.
60-84: Validates fallback for unknown error codes.This test ensures the system can handle unexpected error codes by returning a stringified version of the error object.
86-105: Effectively tests rate limit error scenarios.The test confirms that rate limit errors are properly identified and reported with the appropriate status code (429).
107-127: Comprehensive test for OAuth token errors.This test validates handling of invalid OAuth token errors with appropriate error codes and messages.
129-153: Critical test for the PR objective - expired token handling.This test directly validates the fix implemented in this PR, ensuring that when a token has expired, the system extracts the detailed message from the error.message field. The test data closely resembles a real-world Facebook API response with expiration timestamp information.
155-176: Verifies default message fallback.This test ensures that when both errorMessage and error.message are empty/falsy, the system falls back to the default "Unknown auth error" message, covering an important edge case.
178-197: Validates handling of unrecognized error subcodes.This test ensures proper fallback to the default message when encountering an unknown error subcode, which is important for robustness.
199-220: Tests custom audience specific error handling.This test validates the specific error message for custom audience unavailability, which is relevant to the PR's focus on Facebook Custom Audience functionality.
243-262: Validates unhandled error scenarios.This final test ensures the system can gracefully handle completely unexpected error codes, which is important for production stability.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## develop #4237 +/- ##
===========================================
+ Coverage 91.05% 91.06% +0.01%
===========================================
Files 627 630 +3
Lines 33049 33049
Branches 7818 7826 +8
===========================================
+ Hits 30092 30096 +4
- Misses 2710 2736 +26
+ Partials 247 217 -30 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (4)
src/v0/util/facebookUtils/networkHandler.test.ts (4)
67-92: Consider more descriptive test naming for default error scenario.While the test itself is well-structured, the description could be more specific about what "details are not found" means in this context.
- it('should throw a NetworkError with default message when error details are not found', () => { + it('should throw a NetworkError with stringified error object when error_user_msg is missing', () => {
190-210: Consider clarifying test description for this case.The test name suggests stringifying the error object, but the actual assertion tests for a default message.
- it('should throw a NetworkError with error object as stringified', () => { + it('should throw a NetworkError with default message for unknown error code', () => {
258-279: Unnecessary conditional check in the catch block.The conditional check on line 272 is redundant since
expect.assertions(3)already ensures that the catch block will be executed with a valid error.try { errorResponseHandler(destResponse); } catch (e) { - if (e) { expect(e).toBeInstanceOf(NetworkError); const error = e as CommonErrorType; expect(error.message).toBe('Unhandled error.'); expect(error.status).toBe(500); - } }
1-280: Overall excellent test coverage for the errorResponseHandler function.The test suite provides comprehensive coverage of various error scenarios, with particular attention to Facebook OAuth errors that are the focus of this PR. The tests are well-structured, consistent in format, and verify both error types and messages appropriately.
Consider adding some comments to explain what the various Facebook error codes represent (e.g., 190 for auth errors, 4 and 17 for rate limits, etc.) to improve code maintainability for future developers.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/v0/util/facebookUtils/networkHandler.test.ts(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (8)
- GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image AMD64
- GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image AMD64
- GitHub Check: ingestion-service-test
- GitHub Check: Code Coverage
- GitHub Check: test_and_publish
- GitHub Check: UT Tests
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: Analyze (go)
🔇 Additional comments (10)
src/v0/util/facebookUtils/networkHandler.test.ts (10)
1-9: Well-structured imports and type definition.Clean imports and a clear TypeScript type definition for common errors. This sets the stage for the test suite to follow.
10-19: Good initial test case verifying the happy path.The first test appropriately checks that no error is thrown when there's no error in the response, establishing the baseline behavior of the function.
21-42: Well-written authentication error test.This test correctly verifies that a ConfigurationAuthError is thrown for authentication errors with appropriate message and status. The use of expect.assertions ensures that the catch block is executed.
44-65: Proper testing of network error with detailed error information.This test case effectively validates the NetworkError behavior when specific error details are available in the response.
94-114: Comprehensive test for rate limit error scenario.Good test case covering rate limiting scenarios with appropriate status code (429).
116-137: Complete test for auth error with different subcode.This test complements the earlier auth error test by covering a different error_subcode value.
139-164: Excellent test covering the core PR objective.This test case directly addresses the PR objective of handling expired Facebook access tokens. The detailed error message with token expiration date is properly validated.
166-188: Good edge case handling for empty auth error messages.This test ensures appropriate fallback behavior when an auth error occurs but no specific message is provided.
212-234: Good test for custom audience specific error.This test validates the specific error handling for Custom Audience unavailability, which aligns well with the PR's focus on Facebook Custom Audience auth errors.
236-256: Complete rate limit test with alternative error code.This test complements the earlier rate limit test by covering error code 17, ensuring comprehensive coverage of rate limiting scenarios.
|
Allure Test reports for this run are available at:
|
There was a problem hiding this comment.
Actionable comments posted: 0
♻️ Duplicate comments (1)
src/v0/util/facebookUtils/networkHandler.test.ts (1)
1-1: Table test format successfully implemented.This implementation addresses the previous review comment that requested "Use LLM and convert this into table tests format." The current structure provides a clean, maintainable way to test multiple scenarios.
🧹 Nitpick comments (1)
src/v0/util/facebookUtils/networkHandler.test.ts (1)
199-213: Well-implemented test execution logic.The test.each implementation effectively validates all three critical components of each error:
- The error class type
- The error message content
- The HTTP status code
Consider adding a type guard before the type assertion on line 207 for added safety:
- const error = e as CommonErrorType; + const error = e instanceof Error ? e as CommonErrorType : e;
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/v0/util/facebookUtils/networkHandler.test.ts(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (9)
- GitHub Check: Code Coverage
- GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image ARM64
- GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image AMD64
- GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image AMD64
- GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image ARM64
- GitHub Check: test_and_publish
- GitHub Check: UT Tests
- GitHub Check: ingestion-service-test
- GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (3)
src/v0/util/facebookUtils/networkHandler.test.ts (3)
1-7: Imports and type definition look good.Clean imports of the necessary error classes and the function under test. The CommonErrorType is well-defined and appropriately used in the test implementation.
9-13: Good baseline test for the success case.Starting with a test for the happy path ensures basic functionality is covered before diving into error scenarios.
15-197: Comprehensive test coverage for error scenarios.The table-driven approach provides excellent coverage of various error conditions including:
- Authentication errors with different error codes
- Network errors with different messages
- Rate limiting scenarios
- The custom audience-specific errors addressed in this PR
Your test for expired tokens (lines 100-118) directly addresses the PR objective of handling Facebook Custom Audience access token expiration.
|
Allure Test reports for this run are available at:
|
|
Allure Test reports for this run are available at:
|
|



What are the changes introduced in this PR?
We’re encountering the following error when the Facebook Custom Audience access token has expired:
This error wasn't being handled previously, which led to users seeing a generic base error message in the UI when looking for sample error responses.
We’ve updated the logic to explicitly handle this case by inspecting the error.message field in the payload.
What is the related Linear task?
Resolves INT-3393
Please explain the objectives of your changes below
Put down any required details on the broader aspect of your changes. If there are any dependent changes, mandatorily mention them here
Any changes to existing capabilities/behaviour, mention the reason & what are the changes ?
N/A
Any new dependencies introduced with this change?
N/A
Any new generic utility introduced or modified. Please explain the changes.
N/A
Any technical or performance related pointers to consider with the change?
N/A
@coderabbitai review
Developer checklist
My code follows the style guidelines of this project
No breaking changes are being introduced.
All related docs linked with the PR?
All changes manually tested?
Any documentation changes needed with this change?
Is the PR limited to 10 file changes?
Is the PR limited to one linear task?
Are relevant unit and component test-cases added in new readability format?
Reviewer checklist
Is the type of change in the PR title appropriate as per the changes?
Verified that there are no credentials or confidential data exposed with the changes.