fix: retry transient failures when fetching project/user data on login#503
Draft
posthog[bot] wants to merge 1 commit into
Draft
fix: retry transient failures when fetching project/user data on login#503posthog[bot] wants to merge 1 commit into
posthog[bot] wants to merge 1 commit into
Conversation
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
🧙 Wizard CIRun 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:
Test all apps in a directory:
Test an individual app:
Show more apps
Results will be posted here when complete. |
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.
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 datacomes from the generic fallthrough inhandleApiError(src/lib/api.ts), reached for any non-401/403/404 response with nodetailbody — i.e. a 5xx, network drop, or timeout onGET /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 uncaughtApiErrorthat killed the run.Changes
fetchProjectDataand the siblingfetchUserDatainsrc/lib/api.tswith 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.askForWizardLogininsrc/utils/setup-utils.ts) and abort gracefully, so a momentary backend blip no longer crashes the run with a rawApiError.Test plan
src/lib/__tests__/api.test.tscover: 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.