How to use the tinyrpc.exc.RPCError function in tinyrpc

To help you get started, we’ve selected a few tinyrpc examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mbr / tinyrpc / tests / test_client.py View on Github external
def test_client_raises_error_replies(client, mock_protocol, method_name,
                                     method_args, method_kwargs,
                                     one_way_setting):
    error_response = RPCErrorResponse()
    error_response.error = 'foo'
    mock_protocol.parse_reply = Mock(return_value=error_response)

    with pytest.raises(RPCError):
        client.call(method_name, method_args, method_kwargs, one_way_setting)
github mbr / tinyrpc / tinyrpc / client.py View on Github external
def _send_and_handle_reply(self, req):
        # sends and waits for reply
        reply = self.transport.send_message(req.serialize())

        response = self.protocol.parse_reply(reply)

        if hasattr(response, 'error'):
            raise RPCError('Error calling remote procedure: %s' %\
                           response.error)

        return response
github mbr / tinyrpc / tinyrpc / exc.py View on Github external
class InvalidRequestError(BadRequestError):
    """A request made was malformed (i.e. violated the specification) and could
    not be parsed."""


class InvalidReplyError(BadReplyError):
    """A reply received was malformed (i.e. violated the specification) and
    could not be parsed into a response."""


class MethodNotFoundError(RPCError):
    """The desired method was not found."""


class ServerError(RPCError):
    """An internal error in the RPC system occured."""
github mbr / tinyrpc / tinyrpc / exc.py View on Github external
"""Base class for all excetions thrown by :py:mod:`tinyrpc`."""


class BadRequestError(RPCError):
    """Base class for all errors that caused the processing of a request to
    abort before a request object could be instantiated."""

    def error_respond(self):
        """Create :py:class:`~tinyrpc.RPCErrorResponse` to respond the error.

        :return: A error responce instance or ``None``, if the protocol decides
                 to drop the error silently."""
        raise RuntimeError('Not implemented')


class BadReplyError(RPCError):
    """Base class for all errors that caused processing of a reply to abort
    before it could be turned in a response object."""


class InvalidRequestError(BadRequestError):
    """A request made was malformed (i.e. violated the specification) and could
    not be parsed."""


class InvalidReplyError(BadReplyError):
    """A reply received was malformed (i.e. violated the specification) and
    could not be parsed into a response."""


class MethodNotFoundError(RPCError):
    """The desired method was not found."""
github mbr / tinyrpc / tinyrpc / exc.py View on Github external
#!/usr/bin/env python
# -*- coding: utf-8 -*-

class RPCError(Exception):
    """Base class for all excetions thrown by :py:mod:`tinyrpc`."""


class BadRequestError(RPCError):
    """Base class for all errors that caused the processing of a request to
    abort before a request object could be instantiated."""

    def error_respond(self):
        """Create :py:class:`~tinyrpc.RPCErrorResponse` to respond the error.

        :return: A error responce instance or ``None``, if the protocol decides
                 to drop the error silently."""
        raise RuntimeError('Not implemented')


class BadReplyError(RPCError):
    """Base class for all errors that caused processing of a reply to abort
    before it could be turned in a response object."""
github mbr / tinyrpc / tinyrpc / exc.py View on Github external
class BadReplyError(RPCError):
    """Base class for all errors that caused processing of a reply to abort
    before it could be turned in a response object."""


class InvalidRequestError(BadRequestError):
    """A request made was malformed (i.e. violated the specification) and could
    not be parsed."""


class InvalidReplyError(BadReplyError):
    """A reply received was malformed (i.e. violated the specification) and
    could not be parsed into a response."""


class MethodNotFoundError(RPCError):
    """The desired method was not found."""


class ServerError(RPCError):
    """An internal error in the RPC system occured."""
github mbr / tinyrpc / tinyrpc / server / __init__.py View on Github external
def handle_message(context, message):
            try:
                request = self.protocol.parse_request(message)
            except RPCError as e:
                response = e.error_respond()
            else:
                response = self.dispatcher.dispatch(request)

            # send reply
            self.transport.send_reply(context, response.serialize())