Ejemplo n.º 1
0
    def __create_method(self, obj):
        """Create bounded method."""
        handler = obj._handler
        service_name = obj._service_name
        method = getattr(handler, self.__name__)
        stack = thriftpool.request_stack

        # Apply all returned by signal decorators.
        for sender, decorator in handler_method_guarded.send(sender=handler,
                                                             fn=method):
            if decorator is not None:
                method = decorator(method)

        @wraps(method)
        def inner_method(*args, **kwargs):
            stack.add(handler, method, args, kwargs, service_name)
            with stack:
                try:
                    return method(*args, **kwargs)
                except Exception as exc:
                    # Catch all exceptions here, process they here. Write application
                    # exception to thrift transport.
                    logging.exception(exc)
                    raise TApplicationException(TApplicationException.INTERNAL_ERROR,
                        "({0}) {1}".format(type(exc).__name__, str(exc)))

        return inner_method
Ejemplo n.º 2
0
    def __create_method(self, obj):
        """Create bounded method."""
        handler = obj._handler
        service_name = obj._service_name
        method = getattr(handler, self.__name__)
        stack = thriftpool.request_stack
        allowed_exceptions = (TException, TExceptionBase)

        # Apply all returned by signal decorators.
        for sender, decorator in handler_method_guarded.send(sender=handler,
                                                             fn=method):
            if decorator is not None:
                method = decorator(method)

        @maybe_wraps(method)
        def inner_method(*args, **kwargs):
            """Method that handle unknown exception correctly."""
            stack.add(handler, method, args, kwargs, service_name)
            with stack:
                try:
                    return method(*args, **kwargs)
                except allowed_exceptions:
                    raise
                except Exception as exc:
                    # Catch all exceptions here, process they here. Write
                    # application exception to thrift transport.
                    logger.exception(exc)
                    code = TApplicationException.INTERNAL_ERROR
                    msg = "{0}({1})".format(type(exc).__name__, str(exc))
                    raise TApplicationException(code, msg)

        return inner_method
Ejemplo n.º 3
0
    def __create_method(self, obj):
        """Create bounded method."""
        handler = obj._handler
        service_name = obj._service_name
        method = getattr(handler, self.__name__)
        stack = thriftpool.request_stack

        # Apply all returned by signal decorators.
        for sender, decorator in handler_method_guarded.send(sender=handler,
                                                             fn=method):
            if decorator is not None:
                method = decorator(method)

        @wraps(method)
        def inner_method(*args, **kwargs):
            stack.add(handler, method, args, kwargs, service_name)
            with stack:
                try:
                    return method(*args, **kwargs)
                except Exception as exc:
                    # Catch all exceptions here, process they here. Write application
                    # exception to thrift transport.
                    logging.exception(exc)
                    raise TApplicationException(
                        TApplicationException.INTERNAL_ERROR,
                        "({0}) {1}".format(type(exc).__name__, str(exc)))

        return inner_method
Ejemplo n.º 4
0
    def __create_method(self, obj):
        """Create bounded method."""
        handler = obj._handler
        service_name = obj._service_name
        method = getattr(handler, self.__name__)
        stack = thriftpool.request_stack
        allowed_exceptions = (TException, TExceptionBase)

        # Apply all returned by signal decorators.
        for sender, decorator in handler_method_guarded.send(sender=handler, fn=method):
            if decorator is not None:
                method = decorator(method)

        @maybe_wraps(method)
        def inner_method(*args, **kwargs):
            """Method that handle unknown exception correctly."""
            stack.add(handler, method, args, kwargs, service_name)
            with stack:
                try:
                    return method(*args, **kwargs)
                except allowed_exceptions:
                    raise
                except Exception as exc:
                    # Catch all exceptions here, process they here. Write
                    # application exception to thrift transport.
                    logger.exception(exc)
                    code = TApplicationException.INTERNAL_ERROR
                    msg = "{0}({1})".format(type(exc).__name__, str(exc))
                    raise TApplicationException(code, msg)

        return inner_method