On Tue, Mar 5, 2013 at 12:45 PM, Peter Waller <[email protected]>wrote:

> At the moment, the presence of a KeyError anywhere in the code is
> effectively masked by the the resource not found logic.


A KeyError in Pyramid is only special during traversal while it is
performing __getitem__ lookups on your resource tree. If these happen, then
the previous context in the tree will be used to lookup a view. Any other
time in your code, other than when the traverser is waiting for a return
value from a __getitem__ invocation, a KeyError will count as simply a
regular old instance of Exception. Pyramid supports "exception views" for
handling these various exceptions, but by default they should render a 500
internal server error message, not a "resource not found" (implying a 404).
You should be able to write your own exception views and handle these
errors.

As far as a KeyError within a __getitem__, you have full control over what
happens here. You are responsible for whatever code is invoked within the
__getitem__ and you may put a try:except: around that code and handle the
KeyError however you see fit before returning/raising anything from within
a __getitem__.

If this isn't making sense, you'll need to provide some clearer info on
what you mean by "resource not found" and what exact behavior you're seeing
in your app.

- Michael

-- 
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].
Visit this group at http://groups.google.com/group/pylons-discuss?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to