Created
December 7, 2016 02:21
-
-
Save lxneng/37010d3ef007a598763be583483bd509 to your computer and use it in GitHub Desktop.
quick trick for changing exceptions to json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@view_config(context=HTTPException) | |
def exception_view__upgrade(exc, request): | |
"""if we end with .json, serve json.""" | |
if (request.path[-5:]).lower() == '.json': | |
request.environ['HTTP_ACCEPT'] = "application/json" | |
return exc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment