Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Version 3 (modified by plewis, 13 years ago) (diff)

revert to v1 (despam)

Custom Error Reporting

We're not perfect. Sometimes we don't catch every exception, even after piles of testing. This is why it's a good idea to be told if disaster strikes and one of your pages bombs out. This is a good idea during so-called "beta testing" (otherwise known as "releasing unfinished product") as you can't always rely on your users informing you of such problems.

Here's a brief rundown on how I did it. I won't go in to how to send an E-mail as that's covered better elsewhere, such as Python's documentation.

# Your controller:

    @turbogears.errorhandling.dispatch_error.when("tg_exceptions is not None")
    def unhandled_exception(self, tg_source, tg_errors, tg_exception):
    		# Spam me here, whatever
    		programmer_notified = True
    		programmer_notified = False
    	return dict(tg_template=".templates.unhandled_exception", title="500 Internal error", programmer_notified=programmer_notified)
# And an example template (unhandled_exception.kid in mine)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="" xmlns:py=""

    <title py:content="title">Title</title>

    <h1>Oops! An error occured</h1>
    <p>Something went wonky and we weren't expecting it. Sorry about that. This is commonly known as an &quot;Error 500&quot; or &quot;Internal Server Error&quot;. It means we messed up.</p>
    <p py:if="programmer_notified">A programmer has been notified and will try to fix the problem as soon as possible.</p>
    <p py:if="not programmer_notified">The problem was actually so bad that we couldn't even send an E-mail to our team to sort the problem out! If you keep getting this message, please send us an E-mail with some information about what you were doing when this happened, so we can try and smooth things over :-)</p>
    <p>Our sincerest apologies,</p>
    <p style="font-style: italic">-The Team</p> <!--! No <em> because this is just convention !-->

Of course, you don't really wanna be hiding your exceptions while you're developing, so I recommend commenting out the @turbogears.errorhandling.dispatch_error decorator until people are going to start visiting the site while you're not sitting over the server output.

Bear in mind that this method supresses exception output in the log so there is a chance that the exception could be lost forever.