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

Combining request.error with Pyramid exceptions. #526

Open
jenstroeger opened this issue Jan 16, 2020 · 3 comments
Open

Combining request.error with Pyramid exceptions. #526

jenstroeger opened this issue Jan 16, 2020 · 3 comments
Labels

Comments

@jenstroeger
Copy link
Collaborator

Considering that Pyramid HTTPExceptions inherit from Response and Exception I can raise or return such objects. However, I was wondering how that plays along with Cornice’s request.errors dictionary.

What’s the recommended way of filling that errors dictionary and then raising an HTTP error response—if that’s doable at all?

Something like

request.errors.add("body", "foo", "Invalid foo specified.")
request.errors.status = 404  # Not found
raise HTTPNotFound()

creates a new Response and the errors dictionary isn’t being used, correct?

@jenstroeger
Copy link
Collaborator Author

Addendum Should have tried before I asked. That’s exactly how it works, actually.

@leplatrem, mind if I expand on the documentation a bit? This is quite a handy detail. Or did I miss it somewhere?

@leplatrem
Copy link
Contributor

@jenstroeger Of course! please do!

@jenstroeger
Copy link
Collaborator Author

@leplatrem, done with this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants