|
Jim Dabell
jim-mod-python at jimdabell.com
Tue Aug 24 16:08:20 EDT 2004
> I have been searching through the mailing list
> archives and reading through documentation +
> onlamp.com article trying to find an example of how to
> use the set_error_page() method. If anyone could
> paste up some example code I would really appreciate
> it. Thanks
Sure, suppose you have index.psp. Put this at the top of it:
<% psp.set_error_page('error.psp') %>
And create a file called error.psp in the same directory. This will be just
like a normal PSP file, except it will have an additional variable passed to
it called 'exception'. For example, you could use something like this:
<%
import smtplib, traceback
(exceptionType, exceptionValue, tb) = exception
message = """Subject: Error
An error has occurred with the website.
The exception type is %s
The exception value is %s
A traceback follows:
%s""" % (exceptionType, exceptionValue, traceback.format_tb(tb))
mailServer = smtplib.SMTP('mail.example.com')
mailServer.sendmail('errors at example.com', 'webmaster at example.com', message)
mailServer.quit()
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Error</title>
</head>
<body>
<h1>Error</h1>
<p>
An error has occurred and the administrators have been notified.
</p>
</body>
</html>
I'm sure you can make the page much more friendlier, but this is just an
example :).
--
Jim Dabell
|