Cornices/cornice

Content type of raised exceptions

Opened this issue · 5 comments

Hi everybody. I'm very new to cornice (tried it a couple of years ago without luck (the project was dumped)) and I've managed (after stumbling accross various obstacles) to make the full example run; ah, and please excuse me if my assumption is incorrect...

What differs in my setup from the full example is that thrown exceptions' content-type is text/html and not application/json. Is that the right way to go with cornice or do I have something wrong in my configuration/code? (I'm using cornice 2.4.0)

Natim commented

Yes that's something a bit cumbersome.
That's how we did in Kinto to make them application/json: https://github.com/Kinto/kinto/blob/master/kinto/core/views/errors.py

Do you feel like bringing this behaviour to cornice?

Yes, I think we could offer a default exception view that returns JSON!

Cool! Sounds nice, since it makes things more consistent in terms of responses' content-type.

The timing! I was just looking into exactly the same problem, hacking together a Pyramid-style exception view so that I can catch and handle problems gracefully. The kinto error() view function helps, but feels out of place for a Cornice implementation.

Any updates on such an exception view? It would be handy to be able to use the request.errors in it, and have CORS taken care of…

I don't think we'll have bandwidth to work on that soon, so feel free to start hacking something, we'll be happy to review and guide you through!

Thanks for waking this up ;)