Is it possible to have an error page display a different message depending on what happened? For example, we have a user-friendly page template for the standard_error_message, but it displays the same content for 404 errors and for script errors. Ideally I'd like to be able to say one message for 404 errors, and another for script errors. -jim
Hi Jim, seems Dieter is on vacation :), and nobody else has answered Your question (or I missed the reply ...). I guess the question is answered on some FAQ, but I could not find it ... Anyway, I try to give an answer:
Is it possible to have an error page display a different message depending on what happened?
The most flexible solution is to define a python script with name 'standard_error_message' replacing the original error message template, which is moved to 'general_error_message', and called by the script if this could not find a more special error page.
For example, we have a user-friendly page template for the standard_error_message, but it displays the same content for 404 errors and for script errors. Ideally I'd like to be able to say one message for 404 errors, and another for script errors.
[...] The script could look like this: ## 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, error_message=error_message, error_traceback=error_traceback, error_tb=error_tb) (error_traceback and error_tb usually refer to the same object, the trace back, I guess.) I do not know if there is a more elegant solution (passing all the keyword arguments around explicitly looks clumsy but seems to be necessary to access them properly.) Cheers, Clemens
Thanks. But I have a few questions about that. 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) And if I provide the error_type how would I know it's a Not Found error? -jim ----- Original Message ----- From: "Clemens Klein-Robbenhaar" <robbenhaar@espresto.com> To: "Jim Kutter" <jim@ebizq.net>; <zope@zope.org> Sent: Wednesday, September 11, 2002 12:18 PM Subject: [Zope] Per error error page
Hi Jim,
seems Dieter is on vacation :), and nobody else has answered Your
question
(or I missed the reply ...). I guess the question is answered on some FAQ, but I could not find it ...
Anyway, I try to give an answer:
Is it possible to have an error page display a different message depending on what happened?
The most flexible solution is to define a python script with name 'standard_error_message' replacing the original error message template, which is moved to 'general_error_message', and called by the script if this could not find a more special error page.
For example, we have a user-friendly page template for the standard_error_message, but it displays the same content for 404 errors
and
for script errors. Ideally I'd like to be able to say one message for 404 errors, and another for script errors. [...]
The script could look like this:
## 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, error_message=error_message, error_traceback=error_traceback, error_tb=error_tb)
(error_traceback and error_tb usually refer to the same object, the trace back, I guess.)
I do not know if there is a more elegant solution (passing all the keyword arguments around explicitly looks clumsy but seems to be necessary to access them properly.)
Cheers, Clemens
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)
participants (2)
-
Clemens Klein-Robbenhaar -
Jim Kutter