Cornices/cornice

Combining `request.error` with Pyramid exceptions.

Opened this issue · 3 comments

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?

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?

@jenstroeger Of course! please do!