Errors
All exceptions inherit from SignalRError (which itself inherits from
Exception), so you can catch every library error with one base class.
Exception
└── SignalRError
├── ProtocolError
├── HubException
├── ConnectionClosed
├── ServerTimeout
├── HandshakeTimeout
├── InvocationCanceled
└── NegotiationError
SignalRError
Base class for all aiosignalr errors.
ProtocolError
A malformed or spec-violating message was received. It is fatal for the connection it occurred on: the client logs it and closes the transport.
HubException
A hub invocation failed on the remote endpoint.
- Client: raised by
invoke()/stream()when aCompletioncarries an error (e.g. the hub method raised, or the method does not exist). - Server: raise it from a hub method to send a specific error message back
to the client (its
str()is transmitted verbatim).
ConnectionClosed
The underlying connection was closed while an operation was in flight.
- Raised by
invoke()/stream()/send()if called while notCONNECTED. - Raised when a transport closes unexpectedly and no reconnect policy (or a failed stateful reconnect) can recover the pending call.
ServerTimeout
The remote endpoint stopped sending messages within the configured
server_timeout. The client then closes the connection.
HandshakeTimeout
The hub handshake did not complete within handshake_timeout.
InvocationCanceled
An invocation was cancelled before it completed (for example, the connection was stopped mid-call).
NegotiationError
The POST /negotiate handshake failed (bad status, non-JSON response, server
error property, or too many redirects).
Catching errors
from aiosignalr.errors import ConnectionClosed, HubException, SignalRError
try:
result = await connection.invoke("add", 1, 2)
except HubException as exc:
print("the server rejected the call:", exc)
except ConnectionClosed as exc:
print("the connection was lost:", exc)
except SignalRError as exc: # catches everything else
print("some other aiosignalr error:", exc)