Skip to content

Add failsafe if bog-analytics fails - #223

Merged
UZ9 merged 1 commit into
mainfrom
ryder/analytics-failsafe
Nov 1, 2025
Merged

UZ9 merged 1 commit into
mainfrom
ryder/analytics-failsafe

Conversation

@UZ9

@UZ9 UZ9 commented Oct 27, 2025 •

Copy link
Copy Markdown
Contributor

Addresses #221

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Loading

1 file reviewed, no comments

Edit Code Review Agent Settings | Greptile

@UZ9
UZ9 merged commit 66f0f87 into main Nov 1, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant