Skip to content

fix(mitm): spinner + retry for body load instead of premature "failed" - #389

Merged
jrothrock merged 1 commit into
mainfrom
fix/mitm-body-loading
Sep 2, 2026
Merged

fix(mitm): spinner + retry for body load instead of premature "failed"#389
jrothrock merged 1 commit into
mainfrom
fix/mitm-body-loading

Conversation

@jrothrock

Copy link
Copy Markdown
Collaborator

Expanding a flow fetched its body once and, on any non-2xx, showed "failed to load body" with no retry. But mitmweb serves content.data only after it finalizes the message — so a body fetched the instant a flow is expanded can error while the response is still arriving, especially a streaming/SSE response. It "failed", then loaded fine a second later on a manual re-expand. That's "not ready yet", not a failure.

Fix

BodySlot now tracks a loading/ready/error state:

  • A spinner ("loading body…") shows while fetching, replacing the plain "loading…" text.
  • On error or an empty body while the response is still in flight (no timestamp_end), it retries a few times (6× / 700ms) before giving up — so a not-yet-captured / streaming body resolves on its own.
  • Only after retries are exhausted does it show an honest "couldn't load body: …".

Verified

Playwright with the content endpoint returning 502 twice then the body: spinner shows, no error flash, body renders (pretty-printed JSON) on the 3rd attempt (hits=3, hasBody=true). Screenshots confirmed both states. Typecheck + build pass.

🤖 Generated with Claude Code

Expanding a flow fetched its body once and, on any non-2xx, showed
"failed to load body" with no retry. But mitmweb serves content.data only
after it finalizes the message, so a body fetched the instant a flow is
expanded can error while the response is still arriving — especially a
streaming/SSE response. It "failed", then loaded fine a second later on a
manual re-expand. That's "not ready yet", not a failure.

BodySlot now tracks a loading/ready/error state:
- A spinner ("loading body…") shows while fetching, replacing the plain
  "loading…" text.
- On error OR an empty body while the response is still in flight
  (no timestamp_end), it retries a few times with a short delay before
  giving up — so a not-yet-captured / streaming body resolves on its own.
- Only after retries are exhausted does it show an honest
  "couldn't load body: …".

Verified with Playwright (content endpoint 502s twice then returns the
body): spinner shows, no error flash, body renders on the 3rd attempt.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@jrothrock
jrothrock merged commit 2e60c47 into main Sep 2, 2026
1 check passed
@jrothrock
jrothrock deleted the fix/mitm-body-loading branch September 2, 2026 20:54
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