Skip to content

Fix Google API Availability and a edge case#18150

Merged
charlesBochet merged 5 commits intomainfrom
precheck-google
Feb 25, 2026
Merged

Fix Google API Availability and a edge case#18150
charlesBochet merged 5 commits intomainfrom
precheck-google

Conversation

@neo773
Copy link
Copy Markdown
Member

@neo773 neo773 commented Feb 20, 2026

First run shows a real customer account, and the second run is my account with all the permissions.

SCR-20260221-bmfd

Simulated edge case if user has access to neither

SCR-20260221-bloo

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Feb 20, 2026

Greptile Summary

Fixes Google API availability detection to handle edge case where Google returns generic "Precondition check failed." error instead of specific "service not enabled" message. Adds validation to prevent connection when user has access to neither Gmail nor Calendar.

Changes:

  • Extended isServiceNotEnabledError to recognize generic precondition check failed errors
  • Added early validation in refreshGoogleRefreshToken to throw descriptive error when both services are unavailable
  • Added comprehensive test coverage for both Gmail and Calendar precondition check failed scenarios

Key improvement: Users now get clear error message directing them to contact workspace administrator instead of silently failing or showing confusing error states.

Confidence Score: 4/5

  • Safe to merge with one minor style suggestion
  • The logic is sound and addresses a real edge case encountered in production. Test coverage is comprehensive. One style improvement suggested for error message matching to be more resilient to message variations.
  • No files require special attention

Important Files Changed

Filename Overview
packages/twenty-server/src/engine/core-modules/auth/services/google-apis-service-availability.service.ts Extended error detection logic to handle generic "Precondition check failed." message from Google API
packages/twenty-server/src/engine/core-modules/auth/services/google-apis.service.ts Added validation to throw error when user has access to neither Gmail nor Calendar
packages/twenty-server/src/engine/core-modules/auth/services/google-apis-service-availability.service.spec.ts Added comprehensive test coverage for generic precondition check failed error case

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[User connects Google account] --> B[Check scopes validity]
    B -->|Invalid scopes| C[Throw INSUFFICIENT_SCOPES]
    B -->|Valid scopes| D[Check Gmail & Calendar availability]
    D --> E[checkMessagingAvailability]
    D --> F[checkCalendarAvailability]
    E -->|API Call| G{Gmail API Response}
    F -->|API Call| H{Calendar API Response}
    G -->|Success| I[isMessagingAvailable = true]
    G -->|Service not enabled| J[isMessagingAvailable = false]
    G -->|Precondition check failed| J
    G -->|Other error| K[Throw error]
    H -->|Success| L[isCalendarAvailable = true]
    H -->|Service not enabled| M[isCalendarAvailable = false]
    H -->|Precondition check failed| M
    H -->|Other error| N[Throw error]
    I --> O{Both unavailable?}
    J --> O
    L --> O
    M --> O
    K --> P[Error thrown]
    N --> P
    O -->|Yes| Q[Throw INSUFFICIENT_SCOPES with workspace admin message]
    O -->|No| R[Create/update connected account]
    R --> S[Set up available channels]
Loading

Last reviewed commit: 1b4e49c

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

3 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 3 files

@neo773 neo773 requested a review from charlesBochet February 20, 2026 19:14
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 1 file (changes from recent commits).

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="packages/twenty-server/src/engine/core-modules/auth/services/google-apis-service-availability.service.ts">

<violation number="1" location="packages/twenty-server/src/engine/core-modules/auth/services/google-apis-service-availability.service.ts:136">
P2: The message is lowercased before the contains check, but the search string is capitalized. This makes the precondition check detection always false. Use a lowercase search string to match the normalized text.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 20, 2026

🚀 Preview Environment Ready!

Your preview environment is available at: http://bore.pub:35981

This environment will automatically shut down when the PR is closed or after 5 hours.

…oogle-apis-service-availability.service.ts

Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
@charlesBochet charlesBochet merged commit e7f958c into main Feb 25, 2026
62 checks passed
@charlesBochet charlesBochet deleted the precheck-google branch February 25, 2026 13:02
@twenty-eng-sync
Copy link
Copy Markdown

Hey @neo773! After you've done the QA of your Pull Request, you can mark it as done here. Thank you!

@github-actions
Copy link
Copy Markdown
Contributor

Thanks @neo773 for your contribution!
This marks your 118th PR on the repo. You're top 1% of all our contributors 🎉
See contributor page - Share on LinkedIn - Share on Twitter

Contributions

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.

2 participants