Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to customize error messages #29

Closed
wants to merge 3 commits into from
Closed

Conversation

simonw
Copy link
Owner

@simonw simonw commented Aug 15, 2024

Fixes #28

Add ability to customize error messages in CSRF protection middleware.

  • Add ErrorMessageID enum to asgi_csrf.py for error message IDs.
  • Modify send_csrf_failed function to accept an error message ID and a custom error message function.
  • Update asgi_csrf_decorator function to accept a custom error message function.
  • Update all calls to send_csrf_failed to pass the appropriate error message ID and custom error message function.
  • Add tests in test_asgi_csrf.py to verify the custom error message functionality.
  • Update README.md to document the new custom error message functionality and provide examples.

For more details, open the Copilot Workspace session.

simonw added 2 commits August 14, 2024 17:16
Fixes #28

Add ability to customize error messages in CSRF protection middleware.

* Add `ErrorMessageID` enum to `asgi_csrf.py` for error message IDs.
* Modify `send_csrf_failed` function to accept an error message ID and a custom error message function.
* Update `asgi_csrf_decorator` function to accept a custom error message function.
* Update all calls to `send_csrf_failed` to pass the appropriate error message ID and custom error message function.
* Add tests in `test_asgi_csrf.py` to verify the custom error message functionality.
* Update `README.md` to document the new custom error message functionality and provide examples.

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/simonw/asgi-csrf/issues/28?shareId=XXXX-XXXX-XXXX-XXXX).
No idea why it added this.
@simonw
Copy link
Owner Author

simonw commented Aug 15, 2024

I want the custom error function to fully replace send_csrf_failed, not be called by it.

Copy link

codecov bot commented Aug 15, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (0d25087) to head (7857869).

Additional details and impacted files
@@            Coverage Diff            @@
##              main       #29   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            1         1           
  Lines          175       182    +7     
=========================================
+ Hits           175       182    +7     

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

@simonw
Copy link
Owner Author

simonw commented Aug 15, 2024

I'm going to abandon this and implement it from scratch.

@simonw simonw closed this Aug 15, 2024
@simonw simonw deleted the custom-error-messages branch August 15, 2024 02:33
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.

Ability to customize error messages
1 participant