Ejemplo n.º 1
0
    def display_debugger(self, key, app):
        if key not in app.debugger_link_tracebacks:
            abort(404)
        
        request.debugger_link_debugger_request = True

        reraise(*app.debugger_link_tracebacks[key])
Ejemplo n.º 2
0
    def handle_user_exception(self, e):
        """
        We override the default behavior in order to deal with APIException.
        """
        exc_type, exc_value, tb = sys.exc_info()
        assert exc_value is e

        if isinstance(e, HTTPException) and not self.trap_http_exception(e):
            return self.handle_http_exception(e)

        if isinstance(e, APIException):
            return self.handle_api_exception(e)

        blueprint_handlers = ()
        handlers = self.error_handler_spec.get(request.blueprint)
        if handlers is not None:
            blueprint_handlers = handlers.get(None, ())
        app_handlers = self.error_handler_spec[None].get(None, ())
        if is_flask_legacy():
            for typecheck, handler in chain(blueprint_handlers, app_handlers):
                if isinstance(e, typecheck):
                    return handler(e)
        else:
            for typecheck, handler in chain(blueprint_handlers.items(), app_handlers.items()):
                if isinstance(e, typecheck):
                    return handler(e)

        reraise(exc_type, exc_value, tb)
Ejemplo n.º 3
0
    def handle_user_exception(self, e):
        """
        We override the default behavior in order to deal with APIException.
        """
        exc_type, exc_value, tb = sys.exc_info()
        assert exc_value is e

        if isinstance(e, HTTPException) and not self.trap_http_exception(e):
            return self.handle_http_exception(e)

        if isinstance(e, APIException):
            return self.handle_api_exception(e)

        blueprint_handlers = ()
        handlers = self.error_handler_spec.get(request.blueprint)
        if handlers is not None:
            blueprint_handlers = handlers.get(None, ())
        app_handlers = self.error_handler_spec[None].get(None, ())
        if is_flask_legacy():
            for typecheck, handler in chain(blueprint_handlers, app_handlers):
                if isinstance(e, typecheck):
                    return handler(e)
        else:
            for typecheck, handler in chain(blueprint_handlers.items(),
                                            app_handlers.items()):
                if isinstance(e, typecheck):
                    return handler(e)

        reraise(exc_type, exc_value, tb)
Ejemplo n.º 4
0
 def __exit__(self, exc_type, exc_value, tb):
     exception_name = self.exc_type.__name__
     if exc_type is None:
         self.test_case.fail('Expected exception of type %r' %
                             exception_name)
     elif not issubclass(exc_type, self.exc_type):
         reraise(exc_type, exc_value, tb)
     return True
Ejemplo n.º 5
0
 def __exit__(self, exc_type, exc_value, tb):
     exception_name = self.exc_type.__name__
     if exc_type is None:
         self.test_case.fail('Expected exception of type %r' %
                             exception_name)
     elif not issubclass(exc_type, self.exc_type):
         reraise(exc_type, exc_value, tb)
     return True
Ejemplo n.º 6
0
    def handle_exception(error):
        import traceback
        error_str = traceback.format_exc()
        logger.get("cgi-log").error(error_str)

        if config.debug:
            from flask._compat import reraise
            handler = app.error_handler_spec[None].get(Exception)
            exc_type, exc_value, tb = sys.exc_info()
            reraise(exc_type, exc_value, tb)

        msg = error_str if config.debug else "系统异常"
        return ErrorResponse(msg).output(), 200
Ejemplo n.º 7
0
def handle_url_error(error, endpoint, values):
    """
    Intercept BuildErrors of url_for() using flasks build_error_handler API
    """
    url = overlay_url_for(endpoint, **values)
    if url is None:
        exc_type, exc_value, tb = sys.exc_info()
        if exc_value is error:
            reraise(exc_type, exc_value, tb)
        else:
            raise error
    # url_for will use this result, instead of raising BuildError.
    return url
Ejemplo n.º 8
0
    def handle_exception(error):
        import traceback
        error_str = traceback.format_exc()
        logger.get("cgi-log").error(error_str)

        if config.debug:
            from flask._compat import reraise
            handler = app.error_handler_spec[None].get(Exception)
            exc_type, exc_value, tb = sys.exc_info()
            reraise(exc_type, exc_value, tb)

        msg = error_str if config.debug else "系统异常"
        return DjErrorResponse(msg).output(), 200
Ejemplo n.º 9
0
    def handle_user_exception(self, e):
        """
        override handle_user_exception and redirect the exception to handle_api_exception
        """
        exc_type, exc_value, tb = sys.exc_info()
        assert exc_value is e

        if isinstance(e, APIError):
            return self.handle_api_exception(e)

        # hook HttpException and return handle_api_exception
        if isinstance(e, HTTPException) and not self.trap_http_exception(e):
            # return self.handle_http_exception(e)
            return self.handle_api_exception(e)

        handler = self._find_error_handler(e)

        if handler is None:
            reraise(exc_type, exc_value, tb)
        return handler(e)
Ejemplo n.º 10
0
 def _flush_bg_loading_exception(self):
     exc_info = self._bg_loading_exc_info
     if exc_info is not None:
         self._bg_loading_exc_info = None
         reraise(*exc_info)
Ejemplo n.º 11
0
def reraise():
    exc_type, exc_value, tb = sys.exc_info()
    _compat.reraise(exc_type, exc_value, tb)
Ejemplo n.º 12
0
def reraise_lastexc():
    exc_type, exc_value, tb = sys.exc_info()
    reraise(exc_type, exc_value, tb)
Ejemplo n.º 13
0
 def _flush_bg_loading_exception(self):
     exc_info = self._bg_loading_exc_info
     if exc_info is not None:
         self._bg_loading_exc_info = None
         reraise(*exc_info)
Ejemplo n.º 14
0
def reraise():
    exc_type, exc_value, tb = sys.exc_info()
    _compat.reraise(exc_type, exc_value, tb)
Ejemplo n.º 15
0
def ff_log_exception(exc_info, original_log_exception=None):
    original_log_exception(exc_info)
    exc_type, exc, tb = exc_info
    # re-raise for werkzeug
    reraise(exc_type, exc, tb)
Ejemplo n.º 16
0
Archivo: utils.py Proyecto: bladams/keg
def reraise_lastexc():
    exc_type, exc_value, tb = sys.exc_info()
    reraise(exc_type, exc_value, tb)