-
-
Notifications
You must be signed in to change notification settings - Fork 946
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(errors): default error serializer content negotiation #2190
feat(errors): default error serializer content negotiation #2190
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #2190 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 64 64
Lines 7621 7624 +3
Branches 1244 1246 +2
=========================================
+ Hits 7621 7624 +3 ☔ View full report in Codecov by Sentry. |
c38e21d
to
0e4b6f8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the effort @CaselIT and @copalco!
I agree it would be nice to squeeze it into a major release since it is indeed bordering a breaking change.
I'll review the implementation more in detail later, but unfortunately this needs a bit of design rework as well as it fails my testing with a generic async
handler.
This is a simple test app that I used: import falcon.asgi
import falcon.media
class AsyncHandler(falcon.media.BaseHandler):
async def serialize_async(self, media, content_type):
return f'{media}\n'.encode()
class Resource:
async def on_get(self, req, resp):
if not req.get_param('password'):
raise falcon.HTTPForbidden(title='NotAllowed')
resp.content_type = 'falcon/peregrine'
resp.media = {'msg': 'Hello'}
app = falcon.asgi.App()
app.resp_options.media_handlers['falcon/peregrine'] = AsyncHandler()
app.add_route('/', Resource()) Rendering normal media using my new handler works:
Going via the exception route fails with an internal server error:
|
good catch! fixed it |
@vytas7 updated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, looks good bar some minor remarks (commented inline).
We also need to make a decision on being able to disable XML, and whether to make a breaking change, and disable XML by default.
Updated.
Not too sure about this. Let's merge this one and think about it after |
As discussed on Gitter, we don't want to make a breaking change wrt XML right now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
We would like to use choose from available content type handlers to return error response content in a best format basing on the accept header of the request.
Related Issues
Fixes #2023
Fixes #2349
Pull Request Checklist
This is just a reminder about the most common mistakes. Please make sure that you tick all appropriate boxes. But please read our contribution guide at least once; it will save you a few review cycles!
If an item doesn't apply to your pull request, check it anyway to make it apparent that there's nothing to do.
docs/
.docs/
.versionadded
,versionchanged
, ordeprecated
directives.docs/_newsfragments/
, with the file name format{issue_number}.{fragment_type}.rst
. (Runtowncrier --draft
to ensure it renders correctly.)If you have any questions to any of the points above, just submit and ask! This checklist is here to help you, not to deter you from contributing!
PR template inspired by the attrs project.