Skip to content

InvalidResponseError

Base classes

Name Children Inherits
RequestError
aclientp.exceptions
Raised when a JSON-RPC request fails.

⋔ Inheritance diagram

graph TD
  95970861785792["exceptions.InvalidResponseError"]
  95970857446960["exceptions.RequestError"]
  125067848531296["builtins.Exception"]
  125067848532160["builtins.BaseException"]
  125067848591872["builtins.object"]
  95970857446960 --> 95970861785792
  125067848531296 --> 95970857446960
  125067848532160 --> 125067848531296
  125067848591872 --> 125067848532160

🛈 DocStrings

Bases: RequestError

The peer answered a request with a result that does not match the method's schema.

Raised by the typed v2 calls instead of a bare pydantic.ValidationError, which is kept as __cause__. Code -32603 (Internal error); data holds the method and the validation errors.

Source code in src/aclientp/exceptions.py
class InvalidResponseError(RequestError):
    """The peer answered a request with a result that does not match the method's schema.

    Raised by the typed v2 calls instead of a bare ``pydantic.ValidationError``, which
    is kept as ``__cause__``. Code ``-32603`` (Internal error); ``data`` holds the
    method and the validation errors.
    """

    def __init__(self, method: str, errors: list[ErrorDetails]) -> None:
        super().__init__(-32603, "Invalid response", {"method": method, "errors": errors})
        self.method = method
        """The method whose response was invalid."""
        self.errors = errors
        """The validation errors (pydantic's ``errors()``, without URLs and contexts)."""

    @classmethod
    def from_validation_error(cls, method: str, exc: ValidationError) -> InvalidResponseError:
        """Build the error from a pydantic validation error."""
        return cls(method, exc.errors(include_url=False, include_context=False))

errors instance-attribute

errors = errors

The validation errors (pydantic's errors(), without URLs and contexts).

method instance-attribute

method = method

The method whose response was invalid.

from_validation_error classmethod

from_validation_error(method: str, exc: ValidationError) -> InvalidResponseError

Build the error from a pydantic validation error.

Source code in src/aclientp/exceptions.py
@classmethod
def from_validation_error(cls, method: str, exc: ValidationError) -> InvalidResponseError:
    """Build the error from a pydantic validation error."""
    return cls(method, exc.errors(include_url=False, include_context=False))

:fa-brands-github: Show source on GitHub