fix(shop,invoicing): wrap Stripe/InvoiceXpress fetch failures instead of leaking a bare TypeError (BIT-31961) #256

Merged
spark merged 1 commits from fix/BIT-31961-stripe-invoicexpress-fetch-failed into main 2026-11-08 12:33:32 +00:00
Owner

Summary

  • Follow-up to #133: that PR fixed the desktop download route, but BIT-31961 reopened with the same ERRSIG a week later. Root cause: the hub fingerprints a bare TypeError: fetch failed (no file/line, since native undici errors carry no frame pointing into our code) by component + message shape only — any unwrapped fetch/fetchImpl call site in apps/api collapses into this one indistinguishable signature, so fixing one call site doesn't stop a different one from reopening the same ticket.
  • Audited every remaining fetch/fetchImpl call site in apps/api/src against this exact message. Two were still bare: shop/stripe.ts's createCheckout() (Checkout Sessions) and call() (Connect: accountLink/accountReady/createConnectedAccount/createTransfer), and invoicing/invoicexpress.ts's call(). Everything else (zerozero, Nextcloud/archive CloudClient, VIES, calendar ICS download()) already wraps network failures into a descriptive domain error.
  • Wraps both in try/catch, rethrowing StripeError/InvoicingError (status 0, descriptive message) on network failure — same shape the rest of the codebase already uses. Future occurrences get their own frame/fingerprint instead of colliding into this ticket, and callers that already catch StripeError/InvoicingError (e.g. EarningsService.transfer, InvoicingWorker) degrade gracefully instead of leaking a raw 500.

Test plan

  • apps/api/test/shop.test.ts — new test asserts createCheckout() throws StripeError (not a raw TypeError) on a rejecting fetchImpl.
  • apps/api/test/invoicing.test.ts — new test asserts InvoiceXpress.check() throws InvoicingError on a rejecting fetchImpl.
  • npx vitest run test/shop.test.ts test/invoicing.test.ts test/desktop-updates.test.ts — 27/27 passing.
  • npx tsc --noEmit — no new errors (pre-existing unrelated errors from stale packages/contracts/packages/metadata build output vs. an already-merged main commit; confirmed present on a clean origin/main checkout without this diff).
## Summary - Follow-up to #133: that PR fixed the desktop download route, but BIT-31961 reopened with the same ERRSIG a week later. Root cause: the hub fingerprints a bare `TypeError: fetch failed` (no file/line, since native undici errors carry no frame pointing into our code) by **component + message shape only** — any unwrapped `fetch`/`fetchImpl` call site in `apps/api` collapses into this one indistinguishable signature, so fixing one call site doesn't stop a *different* one from reopening the same ticket. - Audited every remaining `fetch`/`fetchImpl` call site in `apps/api/src` against this exact message. Two were still bare: `shop/stripe.ts`'s `createCheckout()` (Checkout Sessions) and `call()` (Connect: `accountLink`/`accountReady`/`createConnectedAccount`/`createTransfer`), and `invoicing/invoicexpress.ts`'s `call()`. Everything else (zerozero, Nextcloud/archive `CloudClient`, VIES, calendar ICS `download()`) already wraps network failures into a descriptive domain error. - Wraps both in try/catch, rethrowing `StripeError`/`InvoicingError` (status `0`, descriptive message) on network failure — same shape the rest of the codebase already uses. Future occurrences get their own frame/fingerprint instead of colliding into this ticket, and callers that already catch `StripeError`/`InvoicingError` (e.g. `EarningsService.transfer`, `InvoicingWorker`) degrade gracefully instead of leaking a raw 500. ## Test plan - [x] `apps/api/test/shop.test.ts` — new test asserts `createCheckout()` throws `StripeError` (not a raw `TypeError`) on a rejecting `fetchImpl`. - [x] `apps/api/test/invoicing.test.ts` — new test asserts `InvoiceXpress.check()` throws `InvoicingError` on a rejecting `fetchImpl`. - [x] `npx vitest run test/shop.test.ts test/invoicing.test.ts test/desktop-updates.test.ts` — 27/27 passing. - [x] `npx tsc --noEmit` — no new errors (pre-existing unrelated errors from stale `packages/contracts`/`packages/metadata` build output vs. an already-merged main commit; confirmed present on a clean `origin/main` checkout without this diff).
spark added 1 commit 2026-11-08 12:09:31 +00:00
fix(shop,invoicing): wrap Stripe/InvoiceXpress fetch failures instead of leaking a bare TypeError (BIT-31961)
ci / rust (pull_request) Successful in 4m9s
ci / typescript (pull_request) Successful in 8m15s
67c1a33e47
The error hub fingerprints a bare \"TypeError: fetch failed\" with no
frame (native undici errors don't point into our code) by component
and message shape alone — every unwrapped fetch call site in the same
component collapses into one indistinguishable ERRSIG. Fixing the
desktop download route (PR #133) didn't stop this ticket from
reopening, because shop/stripe.ts's createCheckout()/call() (Stripe
Checkout + Connect) and invoicing/invoicexpress.ts's call() also threw
the native fetch error straight through to callers/routes with no
wrapping, unlike every other network client in apps/api (zerozero,
Nextcloud, VIES, calendar ICS).

Wraps both call sites in try/catch and rethrows a StripeError/
InvoicingError (status 0, descriptive message) on network failure —
same pattern Nextcloud's CloudClient and calendar's download() already
use. Gives future occurrences their own frame and fingerprint instead
of colliding into this one.

Paperclip-Agent: José Alves (urlKey jos-alves; id 11179220-3cec-4f0f-880d-2771ff64fce8)
Paperclip-Issue: BIT-31961
Paperclip-Run: 36170d99-50b2-4583-ae8e-ce8cfc898189
paperclip-review-bot left a comment
Member

auto-approve: CI success on 67c1a33e47 (gitea_auto_approve_open_prs_once.py)

auto-approve: CI success on 67c1a33e4797 (gitea_auto_approve_open_prs_once.py)
founding-engineer left a comment
Member

auto-approve: CI success on 67c1a33e47 (gitea_auto_approve_open_prs_once.py)

auto-approve: CI success on 67c1a33e4797 (gitea_auto_approve_open_prs_once.py)
devops-engineer left a comment
Member

auto-approve: CI success on 67c1a33e47 (gitea_auto_approve_open_prs_once.py)

auto-approve: CI success on 67c1a33e4797 (gitea_auto_approve_open_prs_once.py)
spark scheduled this pull request to auto merge when all checks succeed 2026-11-08 12:33:30 +00:00
spark merged commit fc2f9bc652 into main 2026-11-08 12:33:32 +00:00
Sign in to join this conversation.