fix: guard all res.json() calls against non-JSON responses#332
fix: guard all res.json() calls against non-JSON responses#332
Conversation
…tests
- DashboardNav: use silent fallback { count: 0 } on non-JSON response
instead of throwing, preserving best-effort semantics for admin badge
- ExtensionAuth: log error to console before showing generic message
- Add queryClient.test.ts covering JSON guard behavior
https://claude.ai/code/session_01UnMFtYo2iEcKRmEUywaAw9
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (7)
📝 WalkthroughWalkthroughMultiple client-side fetch handlers across components and pages updated to defensively wrap Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
Possibly related PRs
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
Wraps every unguarded
res.json()call across client-side hooks, components, and pages with a.catch()guard so that non-JSON 200 responses (e.g., HTML error pages from a reverse proxy or CDN) produce a descriptive"Unexpected response format from server"error instead of a crypticSyntaxError. Also moves the welcome campaign bootstrap fromregisterRoutestoserver/index.tswith timeout protection, and adds comprehensive test coverage for the new behavior.Fixes #325, #326, #327, #328, #329, #331.
Changes
Client-side JSON parsing guards (~35 call sites)
client/src/lib/queryClient.ts— app-wide defaultqueryFn(highest leverage fix)client/src/components/UpgradeDialog.tsx— Stripe checkout mutationclient/src/components/DashboardNav.tsx— admin error count query (uses silent{ count: 0 }fallback to preserve best-effort semantics)client/src/pages/Support.tsx— contact form mutationclient/src/pages/AdminErrors.tsx— 7 admin query/mutation callsclient/src/pages/ExtensionAuth.tsx— extension token fetch +console.errorin outer catchuse-monitors,use-tags,use-auth,use-conditions,use-notification-channels,use-notification-preferences,use-slack,use-api-keys,use-campaigns)Auth hook improvement
useAuthnow exposesisErroranderrorfields for better error state handlingServer-side refactor
server/routes.tstoserver/index.tswith 5s timeoutregisterRoutes()now returns{ httpServer, campaignConfigsReady }for proper sequencingTest infrastructure
happy-domtojsdomfor msw compatibilityqueryClient.test.tscovering happy path, 401 handling, and non-JSON response guardHow to test
npm run check— TypeScript passes cleanlynpm run test— all 2081 tests pass (84 files)npm run build— production build succeedshttps://claude.ai/code/session_01UnMFtYo2iEcKRmEUywaAw9
Summary by CodeRabbit
Bug Fixes
Tests