[Zope] Per error error page

Clemens Klein-Robbenhaar zope@zope.org
Wed, 11 Sep 2002 19:32:40 +0200 (CEST)


Hi Jim,

 > Where does error_type come from? Isnt' there something in Zope that can tell
 > me what error occurred (similar to dtml-try, but maybe on a global level -
 > I'd hate to wrap all pages with try-catch blocks)

You can find out more in the Zope Developer book, e.g. in the chapter
"Exceptions" at
http://www.zope.org/Documentation/Books/ZDG/current/ObjectPublishing.stx 

Or simply look at lib/python/OFS/SimpleItem.py, method
"raise_standardErrorMessage". (I find that more informative ;-)

The "error_type" should actually be the same You get in the
<dtml-except error_type_here>, and which is defined in the implicit
variable 'error_type' there.

 > 
 > And if I provide the error_type how would I know it's a Not Found error?
 > 

This exceptions are actually raised in
lib/python/ZPublisher/HTTPResponse.py, method "notFoundError".

It is really simply the string "NotFound", which is raised in case of
not findings a requested object, not some class 
(at least for my Zope.2.5.0). Thus my test:
  if error_type=="NotFound": ... 
should work. 

I do not know if there is a reference list of "standard exceptions"
which may be thrown by the ZPublisher directly.
(the objects published by the ZPublisher may raise any kind of
exceptions anyway.) 



 [snip citation]
 > > ## Script (Python) "standard_error_message"
 > > ##bind container=container
 > > ##bind context=context
 > > ##bind namespace=
 > > ##bind script=script
 > > ##bind subpath=traverse_subpath
 > > ##parameters=error_type=None, error_value=None, error_traceback=None,
 > error_tb=None, error_message=None
 > > ##title=
 > > ##
 > >
 > > if str(error_type) == 'NotFound':
 > >   error_page = context.not_found
 > > else:
 > >   error_page = context.general_error_message
 > >
 > > return error_page(error_type=error_type,
 > >                   error_value=error_type,

BTW: stupid typo of mine: should read "error_value=error_value," 
of course.

 > >                   error_message=error_message,
 > >                   error_traceback=error_traceback,
 > >                   error_tb=error_tb)
 > >