[Zope] How do I personalize my error messages?

Jens Vagelpohl jens@digicool.com
Fri, 23 Feb 2001 23:25:24 -0500


404 error messages do go to the standard_error_message. an example of those
that do not would be the failed authentication.

i have a custom standard_error on all of my sites and it works beautifully.
there used to be problems with versions of Zope earlier than 2.2.4 i believe
where customizing wouldn't do much.

and by the way, you will get the hardcoded error message if your
standard_error_message itself throws an error.

see my own standard error message below. it checks for "NotFound" error
types (->404), tries to redirect correctly in case the error came from a
stale bookmark, and as a last resort it prints a message. then it sends mail
to me so i know what failed.

all other errors get a more generic error message and i get mail sent to me
as well.

****************************
<dtml-var name="standard_html_header">

<dtml-if expr="error_type == 'NotFound'">
  <h1>Error 404: Cannot find requested page</h1>
  <p><br></p>

    <dtml-if expr="_.string.replace(URL0, SERVER_URL, '') =='/numbers_html'
or _.string.replace(URL0, SERVER_URL, '')=='/technology_html'">
      <dtml-call expr="RESPONSE.redirect('/technology', status=301,
lock=1)">
    <dtml-elif expr="_.string.replace(URL0, SERVER_URL, '')=='/links_html'">
      <dtml-call expr="RESPONSE.redirect('/sites/links_html' , status=301,
lock=1)">
    <dtml-elif expr="_.string.replace(URL0, SERVER_URL,
'')=='/history_html'">
      <dtml-call expr="RESPONSE.redirect('/history', status=301, lock=1)">
    <dtml-elif expr="_.string.replace(URL0, SERVER_URL,
'')=='/problems_html'">
      <dtml-call expr="RESPONSE.redirect('/technology/problems_html',
status=301, lock=1)">
    <dtml-elif expr="_.string.find(PATH_INFO, 'spares_html') != -1">
      <dtml-call expr="RESPONSE.redirect('/spares', status=301, lock=1)">
    <dtml-elif expr="_.string.replace(URL0, SERVER_URL,
'')=='/pictures/accessories_html'">
      <dtml-call expr="RESPONSE.redirect('/pictures/accessories',
status=301, lock=1)">
    <dtml-elif expr="_.string.find(PATH_INFO, '/pictures/images') != -1 or
_.string.replace(URL0, SERVER_URL, '')=='/pictures/pix_html'">
      <dtml-call expr="RESPONSE.redirect('/pictures', status=301, lock=1)">

    <dtml-else>
      <p>The page you were looking for: </p>
      <p>&nbsp;<dtml-var name="URL0"></p>
      <p>has been moved or removed. The navigation menu to the left has
available choices.</p>

<dtml-sendmail smtphost="xyz.mymail.com">
To: broken_links@mymail.com
From: Broken Link <webmaster@mymail.com>
Subject: [Error] Oops 404

Reported a 404 for the following URL:

<dtml-var name="URL0">

<dtml-if name="REMOTE_HOST">
Requested by Host: <dtml-var name="REMOTE_HOST">
</dtml-if>

<dtml-if name="REMOTE_ADDR">
Requested by Address: <dtml-var name="REMOTE_ADDR">
</dtml-if>

<dtml-if name="HTTP_REFERER">
Linked from: <dtml-var name="HTTP_REFERER">
</dtml-if>

</dtml-sendmail>

  </dtml-if>
  <p><br></p>
  <p>Please adjust your bookmarks!</p>

<dtml-else>

  <h1>A horrible error occurred!</h1>
  <p><br></p>
  <p>A report has been sent to the webmaster.</p>

<dtml-sendmail smtphost="xyz.mymail.com">
To: site_errors@mymail.com
From: Site Errors <webmaster@mymail.com>
Subject: [Error] <dtml-if name="error_type"><dtml-var
name="error_type"><dtml-else>Oops</dtml-if>

Reported an error <dtml-if name="error_type">of type <dtml-var
name="error_type"> </dtml-if>for the following URL:

<dtml-var name="URL0">

<dtml-if name="REMOTE_HOST">
Requested by Host: <dtml-var name="REMOTE_HOST">
</dtml-if>

<dtml-if name="REMOTE_ADDR">
Requested by Address: <dtml-var name="REMOTE_ADDR">
</dtml-if>

<dtml-if name="HTTP_REFERER">
Linked from: <dtml-var name="HTTP_REFERER">
</dtml-if>

<dtml-if name="error_tb">
<dtml-var name="error_tb">
</dtml-if>

</dtml-sendmail>

</dtml-if>

<dtml-var name="standard_html_footer">
**************

hth

jens




on 2/23/01 20:40, Andy McKay at andym@ActiveState.com wrote:

> Bizarre as it seems, not all error messages go to standard_error_message.
> Some obvious ones such as 404 for example. Add yourself to the growing list
> of people who think this is annoying.
> --
> Andy McKay.
> 
> 
> ----- Original Message -----
> From: "Smith, RyanX" <ryanx.smith@intel.com>
> To: <zope@zope.org>
> Sent: Friday, February 23, 2001 5:32 PM
> Subject: [Zope] How do I personalize my error messages?
> 
> 
>> I changed the standard_error_message file but whenever I recieve an error
> my
>> changes are not reflected. I have tried restarting the server and this did
>> not help. Any help would be greatly appreciated.
>> 
>> Thanks
>