Skip to content

docs: add recipe for customizing error handling#2694

Closed
Atishay17 wants to merge 2 commits into
falconry:masterfrom
Atishay17:recipe/error-handling
Closed

docs: add recipe for customizing error handling#2694
Atishay17 wants to merge 2 commits into
falconry:masterfrom
Atishay17:recipe/error-handling

Conversation

@Atishay17

@Atishay17 Atishay17 commented Jul 18, 2026

Copy link
Copy Markdown

Summary of Changes

Adds a new recipe to docs/user/recipes/ demonstrating two ways to
customize Falcon's error handling behavior:

  • Using set_error_serializer to negotiate the error response format
    based on the client's Accept header (JSON vs. plain text).
  • Using add_error_handler to intercept a specific exception type and
    either render a custom response directly, or re-raise it as an
    instance of HTTPError so Falcon renders it as usual.

Both examples are provided for WSGI and ASGI, with accompanying tests
in tests/test_recipes.py. Adapted from the example gist linked in
the issue.

Note: drafted with LLM (Claude) assistance for the initial code/docs
and debugging test failures; all code has been run, tested, and
reviewed by me before submission.

Related Issues

Closes #2692

Pull Request Checklist

  • Applied changes to both WSGI and ASGI code paths and interfaces (where applicable).
  • Added tests for changed code.
  • Performed automated tests and code quality checks by running tox.
  • Prefixed code comments with GitHub nick and an appropriate prefix.
  • Coding style is consistent with the rest of the framework.
  • Updated documentation for changed code.
    • Added docstrings for any new classes, functions, or modules.
    • Updated docstrings for any modifications to existing code.
    • Updated both WSGI and ASGI docs (where applicable).
    • Added references to new classes, functions, or modules to the relevant RST file under docs/.
    • Updated all relevant supporting documentation files under docs/.
    • A copyright notice is included at the top of any new modules (using your own name or the name of your organization).
    • Changed/added classes/methods/functions have appropriate versionadded, versionchanged, or deprecated directives.
  • Changes (and possible deprecations) have towncrier news fragments under docs/_newsfragments/.
  • LLM output, if any, has been carefully reviewed and tested by a human developer.

@codecov

codecov Bot commented Jul 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (9902b95) to head (24d7d40).

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #2694   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           64        64           
  Lines         7987      7987           
  Branches      1105      1105           
=========================================
  Hits          7987      7987           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@vytas7

vytas7 commented Jul 21, 2026

Copy link
Copy Markdown
Member

Hi @Atishay17, and thanks for this PR.
This issue was, OTOH, not looking for contributors -- it was being worked upon in EuroPython '26 Sprints.

Moreover, you marked in the checklist that you ran Tox, but it's not entirely true -- some gates fail.

We will move forward with a version from a human Sprint participant if that gets committed. Otherwise we can circle back on this PR.

@vytas7 vytas7 closed this Jul 21, 2026
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.

Add a recipe showing how to customize error handling

2 participants