Cheers, thanks all for the valuable suggestions. Much appreciated :) Hmm,
plenty of options and lots to think about. Interesting to hear what others
are doing regards this scenario :) Ok will soak up all the info and have a
play around with suggestions. Thanks again :)
On Thursday, 15
Since you explicitly want to return a JSON error (and not adapt a response
for the path) I can offer another strategy (which i use).
This is from memory so the code may need some tweaking. (working from home
today and don't have the source)
1. Define a custom class for JSON exceptions:
At first I always raised HTTPException's to make them more obvious un
the Python code. But after having problems with HTTPNotFound and
HTTPForbidden for similar reasons as yours (although not regarding
JSON), I switched to returning them. The only time I raise
HTTPException views now is if I'm in
On Thu, Dec 15, 2016 at 12:06 PM, 'dcs3spp' via pylons-discuss <
pylons-discuss@googlegroups.com> wrote:
> Cheers Michael. Thanks for responding :)
>
> Can't seem to locate where request is favouring HTML over
> application/json. I have tested using curl request to set the accept and
>
Cheers Mike thanks for the suggestion :) Interesting point regarding
performance overhead of raising the exception. H. Now swaying towards
RETURN HTTPNotFound for missing database record and using a custom notfound
view to return JSON for missing request-URI.
Thanks for all suggestions
On Thu, Dec 15, 2016 at 7:47 AM, 'dcs3spp' via pylons-discuss
wrote:
> In this case is it acceptable to RETURN HTTPNotFound so that I can achieve a
> JSON response?
Yes.
> Or, should I be using a different exception type when a
> resource cannot be located in
Cheers Michael. Thanks for responding :)
Can't seem to locate where request is favouring HTML over application/json.
I have tested using curl request to set the accept and content-type headers
as follows:
curl -i -H "Accept: application/json" -H "Content-Type: application/json"
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