Skip to content

Handle JSON payloads in set-theme action#773

Merged
kentcdodds merged 2 commits intomainfrom
typeerror-content-type-was-upvyw9
Apr 28, 2026
Merged

Handle JSON payloads in set-theme action#773
kentcdodds merged 2 commits intomainfrom
typeerror-content-type-was-upvyw9

Conversation

@kentcdodds
Copy link
Copy Markdown
Owner

@kentcdodds kentcdodds commented Apr 27, 2026

Summary

  • return a 400 response when /action/set-theme receives a non-form body
  • keep the form submission flow (and validation) unchanged

Testing

  • npm run test:all
  • curl -i -X POST http://localhost:3000/action/set-theme -H "Content-Type: application/json" -d '{"theme":"dark"}'
  • Manual: theme toggle in browser

Artifacts

theme-toggle-form-success-trim.mp4

Open in Web Open in Cursor 

Summary by CodeRabbit

Bug Fixes

  • Improved error handling for theme settings. Invalid form submissions now return a clear error message instead of failing unexpectedly.

@cursor
Copy link
Copy Markdown

cursor Bot commented Apr 27, 2026

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 27, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: fb857e3b-c73e-44cb-841a-9c27079d8170

📥 Commits

Reviewing files that changed from the base of the PR and between 4fea22a and 3fa0412.

📒 Files selected for processing (1)
  • services/site/app/routes/action/set-theme.tsx

📝 Walkthrough

Walkthrough

Added defensive error handling to the set-theme action to catch TypeError exceptions from request.formData() calls. When a TypeError occurs, the action now returns a 400 JSON error response instead of propagating the exception. Other error types are rethrown for upstream handling.

Changes

Cohort / File(s) Summary
Error Handling Enhancement
services/site/app/routes/action/set-theme.tsx
Added try-catch wrapper around request.formData() to defensively handle TypeError by returning a 400 JSON response with error message. Downstream Zod validation remains unchanged.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A little try-catch, oh what delight,
Form data now handled, errors made right,
When TypeErrors hop along the way,
We gracefully return a 400 today! 🎀

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The PR title 'Handle JSON payloads in set-theme action' is partially related to the changeset. The actual change adds error handling for non-form bodies (returning 400 for TypeError), not explicit JSON payload support. The title is somewhat broader than the specific implementation. Consider a more precise title like 'Add error handling for non-form bodies in set-theme action' to better reflect the defensive error handling rather than implying JSON support.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch typeerror-content-type-was-upvyw9

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@kentcdodds kentcdodds marked this pull request as ready for review April 27, 2026 16:11
@kentcdodds kentcdodds merged commit 8222a4f into main Apr 28, 2026
11 checks passed
@kentcdodds kentcdodds deleted the typeerror-content-type-was-upvyw9 branch April 28, 2026 02:27
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.

2 participants