Repository navigation
Add failsafe if bog-analytics fails - #223
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Disclaimer: This comment was AI-generated and is not necessarily completely accurate. Please take code comments with a grain of salt.
Greptile Overview
Greptile Summary
Added null/undefined response checks after calling bog-analytics logging methods (logClickEvent, logInputEvent, logVisitEvent, logCustomEvent) to prevent accessing properties on potentially null/undefined responses. When bog-analytics fails or returns falsy values due to invalid configuration, the service now throws a descriptive RpcException with INVALID_ARGUMENT status code instead of causing runtime errors.
- Added identical failsafe checks in all four logging methods
- Each check throws an exception with message "Invalid analytics configuration" if response is falsy
- Prevents downstream errors when trying to access properties like
response._id,response.category, etc.
Confidence Score: 5/5
- This PR is safe to merge with minimal risk
- The changes add defensive programming checks that prevent null/undefined access errors. The implementation is consistent across all four affected methods, uses appropriate error codes and messages, and doesn't modify any existing logic or introduce breaking changes
- No files require special attention
Important Files Changed
File Analysis
| Filename | Score | Overview |
|---|---|---|
| packages/analytics-service/src/modules/analytics/analytics.service.ts | 5/5 | Added null/undefined response checks after bog-analytics logging calls to handle configuration failures gracefully |
Sequence Diagram
sequenceDiagram
participant Client
participant AnalyticsService
participant AnalyticsLogger
participant BogAnalytics
Client->>AnalyticsService: logClickEvent(event)
AnalyticsService->>AnalyticsService: getAnalyticsLogger()
AnalyticsService->>AnalyticsLogger: authenticate(clientKey)
AnalyticsService->>BogAnalytics: logClickEvent(event)
alt Response exists
BogAnalytics-->>AnalyticsService: response object
AnalyticsService->>AnalyticsService: Check if response exists
AnalyticsService-->>Client: Return formatted response
else Response is null/undefined (NEW)
BogAnalytics-->>AnalyticsService: null/undefined
AnalyticsService->>AnalyticsService: Check if response exists
AnalyticsService-->>Client: RpcException: Invalid analytics configuration
end
1 file reviewed, no comments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addresses #221