You are here: home » blog » mail-uncatched-errors-with-google-app-engine » comment-page-1

What's he up to?

Mail uncaught errors with Google App Engine

From Kees van den Broek. February 28, 2010, 1 Comment

A simple script to start off any new GAE project.
All exceptions raised in production will show up in the GAE Logs dashboard, but I prefer to be notified by email.
To prevent email flooding, the same error will only be reported once a day.

class SomeHandler(EmailRequestHandler):
    def get(self):
        # Any unhandled exception here will be mailed.

import traceback
from google.appengine.ext import webapp
from google.appengine.api import memcache, mail
 
class EmailRequestHandler(webapp.RequestHandler):
    """Mail admins on uncaught exceptions.
       Send the same exception only once (per day) 
    """
 
    def handle_exception(self, exception, debug_mode):
        tb = traceback.format_exc()
        already_reported_tb = memcache.get(tb)
        if already_reported_tb is None:
            memcache.add(tb, '1', 60 * 60 * 24)        
            mail.send_mail_to_admins(sender="admin@mydomain.com",
                                     subject="Exception catch-all triggered",
                                     body=tb)
        webapp.RequestHandler.handle_exception(self, exception, debug_mode)

It would be nice to programmatically add the GAE project name as well…

One Response to “Mail uncaught errors with Google App Engine”

  1. JUAN says:


    CheapTabletsOnline.Com. Canadian Health&Care.No prescription online pharmacy.Special Internet Prices.Best quality drugs. Low price pills. Buy drugs online

    Buy:Benicar.Lipothin.Advair.Wellbutrin SR.Amoxicillin.Female Pink Viagra.Aricept.Lipitor.Ventolin.Female Cialis.Lasix.Nymphomax.SleepWell.Prozac.Acomplia.Buspar.Zetia.Seroquel.Cozaar.Zocor….

Leave a Reply


last modified on 2010-09-06 @ 10:12