Skip to content

fix(calendar): handle not-connected gracefully without throwing#855

Open
AggManik wants to merge 2 commits into
mainfrom
fix/calendar-widget-not-connected
Open

fix(calendar): handle not-connected gracefully without throwing#855
AggManik wants to merge 2 commits into
mainfrom
fix/calendar-widget-not-connected

Conversation

@AggManik
Copy link
Copy Markdown
Contributor

Summary

  • Guards against undefined workspaceId (JWT/API-key auth does not always include workspace context). Previously the as string cast let undefined reach Prisma, which can throw a validation error in strict mode — causing the widget to show "Could not load events" instead of "Connect Google Calendar".
  • Wraps getConnectedIntegrationAccounts in try-catch so any unexpected DB error returns connected: false rather than propagating a 500 that the widget misreads as connected: true.
  • Short-circuits on result.isError before JSON.parse so explicit integration error responses set the correct error state.

Before

When Google Calendar was not connected (and workspaceId was undefined in auth context), the route threw → widget catch set connected: true, error: true → showed "Could not load events" instead of "Connect Google Calendar".

After

All three failure modes (workspaceId missing, DB error, no accounts) return { connected: false }, which the widget renders as the proper not-connected empty state.

Test plan

  • Add calendar widget to Daily page without Google Calendar connected — should show "Connect Google Calendar" link
  • Connect Google Calendar and reload — should show today's events or "No events today"
  • Revoke Google Calendar token — should show "Could not load events" with Retry button
  • Access route via JWT without workspaceId in token — should return { connected: false } HTTP 200, not 500

🤖 Generated with Claude Code

AggManik and others added 2 commits May 15, 2026 12:28
- New native widget CalendarWidget renders today's events sorted by
  start time, with all-day events at the top
- New API route GET /api/v1/calendar/today-events fetches events via
  the google-calendar integration using the user's local timezone
- Registers "calendar" in NATIVE_WIDGETS so users can add it via the
  widget picker in the Daily section
- Updates google-calendar list_events to return structured JSON instead
  of a formatted string so the route can parse event objects cleanly

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…out throwing

- Guard against undefined workspaceId (possible for JWT/API-key auth) by
  returning connected:false instead of passing undefined to Prisma which
  can throw a validation error in strict mode
- Wrap getConnectedIntegrationAccounts in try-catch so any DB error returns
  connected:false rather than propagating a 500 that the widget misreads
  as connected:true
- Short-circuit on result.isError before attempting JSON.parse so explicit
  integration error responses return the correct error state

Fixes: calendar widget shows "Could not load events" instead of
"Connect Google Calendar" when calendar is not connected

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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