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

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. CARLOS says:


    Medicamentspot.com. Canadian Health&Care.Best quality drugs.Special Internet Prices.No prescription online pharmacy. Online Pharmacy. Buy pills online

    Buy:Viagra Super Force.Cialis Soft Tabs.Maxaman.VPXL.Zithromax.Cialis.Viagra Soft Tabs.Cialis Professional.Super Active ED Pack.Soma.Viagra Super Active+.Viagra.Cialis Super Active+.Levitra.Propecia.Viagra Professional.Tramadol….

Leave a Reply


last modified on 2010-02-23 @ 15:10