probably at the beach
probably at the beach

Reputation: 15227

500 errors on appengine and console

I'm using Google Appengine in a production environment and we are currently getting 500 errors on both our website and console. Is there anything we can do to prevent these or handle them more gracefully?

EDIT: We're using python with Webapp

Upvotes: 2

Views: 345

Answers (1)

moraes
moraes

Reputation: 13649

  1. Setup error handlers: http://code.google.com/appengine/docs/python/config/appconfig.html#Custom_Error_Responses

  2. When the error occurs in the app, error handlers can't help. One solution is to wrap the application to handle uncaught exceptions:

    import logging
    
    from google.appengine.ext import webapp
    from google.appengine.ext.webapp import util
    
    def error_handler_middleware(app):
        """Wraps the application to catch uncaught exceptions."""
        def wsgi_app(environ, start_response):
            try:
                return app(environ, start_response)
            except Exception, e:
                logging.exception(e)
                # ... display a custom error message ...
                response = webapp.Response()
                response.set_status(500)
                response.out.write('Ooops! An error occurred...')
                response.wsgi_write(start_response)
                return ['']
    
        return wsgi_app
    
    app = webapp.WSGIApplication([...])
    app = error_handler_middleware(app)
    
    def main():
        util.run_wsgi_app(app)
    
    if __name__ == '__main__':
        main()
    
  3. If you can, give webapp2 a try. You can set simple functions to handle app-wide exceptions.

Upvotes: 2

Related Questions