Skip to content

fix: retry transient failures when fetching project/user data on login#503

Draft
posthog[bot] wants to merge 1 commit into
mainfrom
posthog-code/retry-transient-fetch-project-data
Draft

fix: retry transient failures when fetching project/user data on login#503
posthog[bot] wants to merge 1 commit into
mainfrom
posthog-code/retry-transient-fetch-project-data

Conversation

@posthog
Copy link
Copy Markdown

@posthog posthog Bot commented Jun 3, 2026

Problem

A wizard run aborted during OAuth login when the call to fetch the user's project data failed with a transient backend/network error, blocking PostHog setup before it could begin.

The message ApiError: Failed to fetch project data comes from the generic fallthrough in handleApiError (src/lib/api.ts), reached for any non-401/403/404 response with no detail body — i.e. a 5xx, network drop, or timeout on GET /api/projects/{id}/. The call originates in the OAuth login path (askForWizardLogin), which fetched the scoped team's project data immediately after region detection with no retry or backoff, so one transient hiccup surfaced as an uncaught ApiError that killed the run.

Changes

  • Wrap fetchProjectData and the sibling fetchUserData in src/lib/api.ts with a small exponential-backoff retry (3 attempts, 500ms base, 4s cap) for transient failures — 5xx server errors and network errors/timeouts (no HTTP response). Definite failures (401/403/404 and malformed payloads / ZodError) are left to fail fast on the first attempt.
  • Surface a clearer, retryable message from the OAuth login flow (askForWizardLogin in src/utils/setup-utils.ts) and abort gracefully, so a momentary backend blip no longer crashes the run with a raw ApiError.

Test plan

  • New unit tests in src/lib/__tests__/api.test.ts cover: retry-and-succeed on 5xx and on network error, give-up after max attempts on persistent 5xx, and no-retry on 401/403/404.
  • pnpm build && pnpm test && pnpm lint — full suite (370 tests) passes, lint reports 0 errors.

Created with PostHog Code from an inbox report.

A momentary 5xx, network drop, or timeout on GET /api/projects/{id}/
during OAuth login surfaced as an uncaught ApiError that aborted the
wizard before PostHog setup could begin.

Wrap fetchProjectData and fetchUserData in src/lib/api.ts with
exponential-backoff retry (3 attempts, 500ms base, 4s cap) for
transient failures (5xx / network / timeout), while leaving definite
failures (401/403/404, malformed payloads) to fail fast. Surface a
clearer, retryable message from the OAuth login flow so a backend blip
no longer crashes the run.

Generated-By: PostHog Code
Task-Id: cdf961ce-d947-43ca-9b2c-9b1a8d1cc01b
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 3, 2026

🧙 Wizard CI

Run the Wizard CI and test your changes against wizard-workbench example apps by replying with a GitHub comment using one of the following commands:

Test all apps:

  • /wizard-ci all

Test all apps in a directory:

  • /wizard-ci basic-integration
  • /wizard-ci misc
  • /wizard-ci revenue

Test an individual app:

  • /wizard-ci basic-integration/android
  • /wizard-ci basic-integration/angular
  • /wizard-ci basic-integration/astro
Show more apps
  • /wizard-ci basic-integration/django
  • /wizard-ci basic-integration/fastapi
  • /wizard-ci basic-integration/flask
  • /wizard-ci basic-integration/javascript-node
  • /wizard-ci basic-integration/javascript-web
  • /wizard-ci basic-integration/laravel
  • /wizard-ci basic-integration/next-js
  • /wizard-ci basic-integration/nuxt
  • /wizard-ci basic-integration/python
  • /wizard-ci basic-integration/rails
  • /wizard-ci basic-integration/react-native
  • /wizard-ci basic-integration/react-router
  • /wizard-ci basic-integration/sveltekit
  • /wizard-ci basic-integration/swift
  • /wizard-ci basic-integration/tanstack-router
  • /wizard-ci basic-integration/tanstack-start
  • /wizard-ci basic-integration/vue
  • /wizard-ci misc/quack-quack
  • /wizard-ci revenue/stripe

Results will be posted here when complete.

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.

0 participants