Skip to content

feat: add headers support to HTTPException and auto-handle in router#1372

Open
sansyrox wants to merge 1 commit into
mainfrom
feat/http-exception-headers
Open

feat: add headers support to HTTPException and auto-handle in router#1372
sansyrox wants to merge 1 commit into
mainfrom
feat/http-exception-headers

Conversation

@sansyrox

Copy link
Copy Markdown
Member

Summary

  • HTTPException now accepts an optional headers dict that gets included in the HTTP response when the exception is raised.
  • Automatic HTTPException handling in the router: when a handler raises HTTPException, the framework catches it and returns the correct Response with the appropriate status code, headers, and detail message — no manual @app.exception handler needed.
  • HTTPException is now exported from the top-level robyn package for convenient imports (from robyn import HTTPException).

Changes

File Change
robyn/exceptions.py Added headers: dict | None = None parameter to HTTPException.__init__
robyn/router.py Added HTTPException catch block in both async_inner_handler and inner_handler (before the generic Exception catch)
robyn/__init__.py Added HTTPException to imports and __all__
unit_tests/test_http_exception.py New test file with 5 unit tests covering default, custom detail, headers, __str__, and __repr__

Test plan

  • test_http_exception_default — verifies default detail from HTTP status phrase and empty headers
  • test_http_exception_custom_detail — verifies custom detail override
  • test_http_exception_with_headers — verifies headers dict is stored and accessible
  • test_http_exception_str — verifies string representation
  • test_http_exception_repr — verifies repr contains class name and status code
  • Verify CI passes on all supported Python versions

Made with Cursor

HTTPException now accepts an optional `headers` dict. When raised inside
a route handler, the framework automatically catches it and returns the
appropriate HTTP response — no manual `@app.exception` handler needed.

Made-with: Cursor
@vercel

vercel Bot commented Apr 11, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
robyn Ready Ready Preview, Comment Apr 11, 2026 11:38pm

@coderabbitai

coderabbitai Bot commented Apr 11, 2026

Copy link
Copy Markdown
Contributor

Warning

Rate limit exceeded

@sansyrox has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 2 minutes and 13 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 2 minutes and 13 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9c8606dd-5a3d-451f-8b5d-9f673f6deeb6

📥 Commits

Reviewing files that changed from the base of the PR and between 3e04c65 and ee4656a.

📒 Files selected for processing (4)
  • robyn/__init__.py
  • robyn/exceptions.py
  • robyn/router.py
  • unit_tests/test_http_exception.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/http-exception-headers

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.

@codspeed-hq

codspeed-hq Bot commented Apr 12, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 189 untouched benchmarks


Comparing feat/http-exception-headers (ee4656a) with main (3e04c65)

Open in CodSpeed

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