Flask Snippets

This is an archived view of user-submitted snippets. Despite being
hosted on the Flask site, they are not official. No Flask
maintainer has curated or checked the snippets for security,
correctness, or design.

Content negotiated error responses

Posted by Jökull Sólberg Auðunsson
on 2012-07-22 @ 21:24
and filed in Utilities

If you would like to trigger an HTTP exception like `abort` in Flask does, but prefer application/json this is one way to do it. You can raise with any JSON serializable object. If the user agent is a browser it will fall back to the Werkzeug errors which are HTML formatted.