コード例 #1
0
ファイル: app.py プロジェクト: nskrypnik/NoodlesFramework
def noodlesapp(env, start_response):
    # Get request object
    request = Request(env)
    #print "Try to handle url_path '%s'" % request.path
    # Get callable object with routine method to handle request
    callable_obj = dispatcher.get_callable(request)
    if not callable_obj:
        # May be here an error,raise exception
        raise Exception('Can\'t find callable for this url path')
    # Callable function must return Respone object
    for middleware in app_middlewares:
        # Hardcoded use of HTTP Session middleware
        callable_obj = middleware(callable_obj)
    try:
        response = callable_obj()
        return response(env, start_response)
    # Capture traceback here and send it if debug mode
    except Exception as e:
        f = logging.Formatter()
        traceback = f.formatException(sys.exc_info())
        # Don't remove this print
        print traceback  # Show traceback in console
        if DEBUG:
            response = Error500(e, traceback)
        else:
            response = Error500()
            MailMan.mail_send(MailMan(), e.__repr__(), traceback)
        return response(env, start_response)
コード例 #2
0
def noodlesapp(env, start_response):
    # Get request object
    request = Request(env)
    #print "Try to handle url_path '%s'" % request.path
    # Get callable object with routine method to handle request
    callable_obj = dispatcher.get_callable(request)
    if not callable_obj:
        # May be here an error,raise exception
        raise Exception('Can\'t find callable for this url path')
    # Callable function must return Respone object
    for middleware in app_middlewares:
        # Hardcoded use of HTTP Session middleware
        callable_obj = middleware(callable_obj)
    try:
        response = callable_obj()
        return response(env, start_response)
    # Capture traceback here and send it if debug mode
    except Exception as e:
        f = logging.Formatter()
        traceback = f.formatException(sys.exc_info())
        # Don't remove this print
        print traceback  # Show traceback in console
        if DEBUG:
            response = Error500(e, traceback)
        else:
            response = Error500()
            MailMan.mail_send(MailMan(), e.__repr__(), traceback)
        return response(env, start_response)
コード例 #3
0
 def onerror(self, e):
     """
     Send here Exception and traceback by Error channel
     """
     f = logging.Formatter()
     traceback = f.formatException(sys.exc_info())
     if DEBUG:
         err_message = {
             'chid': WS_CHANNELS['ERROR_CHID'],
             'pkg': {
                 'exception': e.__repr__(),
                 'tb': traceback
             }
         }
     else:
         err_message = {
             'chid': WS_CHANNELS['ERROR_CHID'],
             'pkg': {
                 'exception': 'error 500',
                 'tb': 'an error occured'
             }
         }
         MailMan.mail_send(MailMan(), e.__repr__(), traceback)
     self.websocket.send(json.dumps(err_message, separators=(', ', ':')))
     print traceback
コード例 #4
0
 def onerror(self, e):
     """
     Send here Exception and traceback by Error channel
     """
     f = logging.Formatter()
     traceback = f.formatException(sys.exc_info())
     if DEBUG:
         err_message = {'chid': WS_CHANNELS['ERROR_CHID'],
                    'pkg': {'exception': e.__repr__(), 'tb': traceback}}
     else:
         err_message = {'chid': WS_CHANNELS['ERROR_CHID'],
                    'pkg': {'exception': 'error 500',
                            'tb': 'an error occured'}}
         MailMan.mail_send(MailMan(), e.__repr__(), traceback)
     self.websocket.send(json.dumps(err_message, separators=(', ', ':')))
     print traceback