How To Customize Error Messages
When a runtime or design-time error occurs, Plone shows a default error page titled 'Our Apologies...' if the error is the 404 or it gives a brief description of the error along with the line number on which the error occurred. A developer would wish to view this default error page, during the testing of the application since the description helps him in rectifying the error. But he would never want a user trying to access his application, to view this error page. The user would be least bothered to know about the error. Instead of showing the default error page, it would be more sensible to show a customized error page that would let the user send notification of the error to the administrator.
The 404 error
Let's suppose we want to detect the 404 and display and we want to display a page with title ' This page does not exist ' and message 'This page does not exist, if you think that it would be important for our site, please contact us'.
First of all we go to the root of our plone site in the ZMI and find the 'default_error_message' page, which is in portal_skins/plone/templates. Customize this page by choosing the folder (eg.custom) where you want the file to be and clicking on the Customize button.
The part which is responsible for the 404 handing is the following:
<div tal:condition="python:err_type=='NotFound'>
.....
</div>
If we want our message to be displayed we have therefore to replace the content of the div like that:
<div tal:condition="python:err_type=='NotFound'>
<h1 i18n:translate="heading_site_error_apologies">This page does not exist</h1>
<p i18n:translate="description_site_error_does_not_exist">
This page does not exist, if you think that it would be important for our site, please contact us.
</p>
</div>
Other errors
If we look further down the code, we note that there is another div:
<div tal:condition="python: err_type!='NotFound'">
This is the part of the code responsible of the general site error message, the one which displays information useful to developers such as the brief description of the error. Therefore if we want to customize our page further, we just need to repeat the steps as for the 404 and our work is done.
