Cheers Mike thanks for the suggestion :) Interesting point regarding performance overhead of raising the exception. Hmmmm. 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 regarding debugging, etc. Very helpful insight :) Cheers Simon On 15 December 2016 at 19:14, Mike Orr <[email protected]> wrote: > On Thu, Dec 15, 2016 at 7:47 AM, 'dcs3spp' via pylons-discuss > <[email protected]> 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 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? > > It's your decision whether the user should see 404 Not Found or > another status. The HTTP definition of 404 is flexible and can mean > anything from "invalid URL" to "record not in database" to "I don't > want to tell you why". Some people use it for security (over > HTTPForbidden) to avoid revealing that that URL would ever give a 200 > response to anybody. > > So if you want the user to see a JSON HTTPNotFound, just return it. > Raising it tells Pyramid to catch it and create another response via > the notfound view mechanism. That's unnecessary overhead and puts the > response details out of the original view's control. If Pyramid's > default notfound view doesn't return JSON when you want it to, then > you should configure a custom notfound view that does. > > If you want to troubleshoot the default notfound view, you can copy it > from the Pyramid source, configure it as your notfound view, and > insert debugging statements to see what the Accept: header is at that > point and whether there's a bug in the function. > > -- > Mike Orr <[email protected]> > > -- > You received this message because you are subscribed to a topic in the > Google Groups "pylons-discuss" group. > To unsubscribe from this topic, visit https://groups.google.com/d/ > topic/pylons-discuss/Rm9S34IM9fY/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > [email protected]. > To post to this group, send email to [email protected]. > To view this discussion on the web visit https://groups.google.com/d/ > msgid/pylons-discuss/CAH9f%3DuoJk-N%3DbA%2B2A- > HTCMEu8JhyMSw%2BOgv56bcCgUV6%3DK%2B5Nw%40mail.gmail.com. > For more options, visit https://groups.google.com/d/optout. > -- 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 [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/pylons-discuss/CAEJBWeiZ5kQMBKC%2BCgQ%3D7Nfg3BjZMvxr%3Dvw-T-ws-K8%2BvhNfBg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
