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

feat: problem details plugin #3323

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open

feat: problem details plugin #3323

wants to merge 24 commits into from

Conversation

peterschutt
Copy link
Contributor

Description

A plugin to enable usage of problem details as the response.

The way this works is by injecting an exception handler into the app level exception handlers to convert ProblemDetailsException into a response following the specification as per RFC 9457.

Users can pass in a mapping of exception types to callables that will convert those exception types into ProblemDetailsException for handling specific exceptions such as pydantic's ValidationError. That converted ProblemDetailsException will then be used to create the response. This should allow for flexibility when needed.

Closes

Closes #3199.

kedod and others added 4 commits April 6, 2024 08:48
* feat: Added precedence of CLI parameters over envs

* Update docs/usage/cli.rst

Co-authored-by: Peter Schutt <peter.github@proton.me>

* Remove redundant LitestarEnv fields and fix tests

* Update docs/usage/cli.rst

* Update litestar/cli/commands/core.py

* Update docs/usage/cli.rst

* Update docs/usage/cli.rst

* Update litestar/cli/commands/core.py

---------

Co-authored-by: kedod <kedod>
Co-authored-by: Peter Schutt <peter.github@proton.me>
Co-authored-by: Jacob Coffee <jacob@z7x.org>
@peterschutt peterschutt requested review from a team as code owners April 5, 2024 22:50
Copy link

github-actions bot commented Apr 5, 2024

It looks like you are adding a new feature! 🚀 Please rebase and point your PR to the develop branch.

@github-actions github-actions bot added size: small type/feat area/plugins This PR involves changes to the plugins pr/internal labels Apr 8, 2024
Copy link

codecov bot commented Apr 8, 2024

Codecov Report

Attention: Patch coverage is 96.42857% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 98.27%. Comparing base (0d0971c) to head (a2b3d02).

❗ Current head a2b3d02 differs from pull request most recent head 9638ed1. Consider uploading reports for the commit 9638ed1 to get more accurate results

Files Patch % Lines
litestar/plugins/problem_details.py 96.42% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3323      +/-   ##
==========================================
- Coverage   98.28%   98.27%   -0.01%     
==========================================
  Files         324      325       +1     
  Lines       14774    14830      +56     
  Branches     2344     2352       +8     
==========================================
+ Hits        14520    14574      +54     
- Misses        116      117       +1     
- Partials      138      139       +1     

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

Copy link
Member

@cofin cofin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. This looks useful. LGTM

guacs and others added 4 commits April 9, 2024 09:13
If `extra` is a `Mapping` then we'll merge that into the final problem
details JSON to keep it similar to how it is in the RFC.
@bunny-therapist
Copy link

What is the status on this?

@peterschutt
Copy link
Contributor Author

What is the status on this?

At risk of stating the obvious, it looks like its waiting on some comments to be resolved and a rebase.

@JacobCoffee JacobCoffee requested a review from guacs April 18, 2024 00:40
@JacobCoffee JacobCoffee added this to the 2.9.0 milestone Apr 18, 2024
@guacs
Copy link
Member

guacs commented Apr 18, 2024

What is the status on this?

I'll get it fixed in a few days. I've been a bit busy.

Co-authored-by: Jacob Coffee <jacob@z7x.org>
Copy link

Documentation preview will be available shortly at https://litestar-org.github.io/litestar-docs-preview/3323

@github-actions github-actions bot added the area/docs This PR involves changes to the documentation label Apr 21, 2024
@guacs guacs requested a review from JacobCoffee April 21, 2024 03:30
Copy link

sonarcloud bot commented Apr 21, 2024

problem_details.update(extra)
else:
problem_details["extra"] = extra

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't there some strange redundancy in these conditionals?
Both L88 and L91 check if self.extra is a Mapping, meaning that if it is a Mapping, L92 will never happen. Right?

To me, it looks like L91-93 can be removed and L94 can be unindented one step to replace the whole interior conditional.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/docs This PR involves changes to the documentation area/plugins This PR involves changes to the plugins pr/internal size: medium type/feat
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enhancement: Support for RFC 7807 / 9457
6 participants