Hi, Wonder if anyone can help/advise with this query.
I am using the built in HTTPException hierarchy to raise a JSON exception with the use of content_type and body parameters, e.g. *raise HTTPBadRequest (content_type='application/json', body=json.dumps(myErrorDict)). * This works fine rendering JSON for exception types other than HTTPNotFound and HTTPForbidden. The documentation at http://docs.pylonsproject.org/projects/pyramid/en/latest/api/httpexceptions.html#module-pyramid.httpexceptions states that when these types of exception are RAISED the appropriate default view (not found or forbidden) will be called. This is indeed the case when testing and always appear to be rendered as HTML, despite setting the content_type and body parameters as JSON. I have noticed that if I RETURN HttpNotFound exception as a response then JSON is rendered, e.g. *return HTTPNotFound (content_type='application/json', body=json.dumps(myErrorDict))* In my application I raise a HTTPNotFound exception whenever a resource id for a GET request cannot be found in the backend database. Currently this directs me to the HTML landing view for not found errors. In this case is it acceptable to RETURN HTTPNotFound so that I can achieve a JSON response? Or, should I be using a different exception type when a resource cannot be located in the database? This way I am not confusing HTTPNotFound exception with the scenario where the server did not find anything matching the Request-URI? What are other developers opinions on this? Cheers Simon -- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discuss+unsubscr...@googlegroups.com. To post to this group, send email to pylons-discuss@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/pylons-discuss/b3d1eb75-5e46-409d-95a5-dc10061b9009%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.