Skip to content

Commit 2c3ba73

Browse files
committed
docs
1 parent 8481411 commit 2c3ba73

File tree

2 files changed

+29
-14
lines changed

2 files changed

+29
-14
lines changed

livekit-rtc/livekit/rtc/participant.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ async def perform_rpc(
286286
FfiClient.instance.queue.unsubscribe(queue)
287287

288288
if cb.perform_rpc.HasField("error"):
289-
raise RpcError.from_proto(cb.perform_rpc.error)
289+
raise RpcError._from_proto(cb.perform_rpc.error)
290290

291291
return cb.perform_rpc.payload
292292

@@ -431,7 +431,7 @@ async def run_handler():
431431
rpc_method_invocation_response=RpcMethodInvocationResponseRequest(
432432
local_participant_handle=self._ffi_handle.handle,
433433
invocation_id=invocation_id,
434-
error=response_error.to_proto() if response_error else None,
434+
error=response_error._to_proto() if response_error else None,
435435
payload=response_payload,
436436
)
437437
)

livekit-rtc/livekit/rtc/rpc.py

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ class RpcError(Exception):
4141
4242
Instances of this type, when thrown in a method handler, will have their `message`
4343
serialized and sent across the wire. The caller will receive an equivalent error on the other side.
44-
45-
Build-in types are included but developers may use any string, with a max length of 256 bytes.
44+
45+
Built-in errors are included (codes 1001-1999) but developers may use the code, message, and data fields to create their own errors.
4646
"""
4747

4848
class ErrorCode(IntEnum):
@@ -83,27 +83,42 @@ def __init__(
8383
Creates an error object with the given code and message, plus an optional data payload.
8484
8585
If thrown in an RPC method handler, the error will be sent back to the caller.
86-
87-
Error codes 1001-1999 are reserved for built-in errors (see RpcError.ErrorCode for their meanings).
86+
87+
Args:
88+
code (int): Your error code (Error codes 1001-1999 are reserved for built-in errors)
89+
message (str): A readable error message.
90+
data (Optional[str]): Optional additional data associated with the error (JSON recommended)
8891
"""
8992
super().__init__(message)
90-
self.code = code
91-
self.message = message
92-
self.data = data
93+
self._code = code
94+
self._message = message
95+
self._data = data
96+
97+
@property
98+
def code(self) -> int:
99+
"""Error code value. Codes 1001-1999 are reserved for built-in errors (see RpcError.ErrorCode for their meanings)."""
100+
return self._code
101+
102+
@property
103+
def message(self) -> str:
104+
"""A readable error message."""
105+
return self._message
106+
107+
@property
108+
def data(self) -> Optional[str]:
109+
"""Optional additional data associated with the error (JSON recommended)."""
110+
return self._data
93111

94112
@classmethod
95-
def from_proto(cls, proto: proto_rpc.RpcError) -> "RpcError":
113+
def _from_proto(cls, proto: proto_rpc.RpcError) -> "RpcError":
96114
return cls(proto.code, proto.message, proto.data)
97115

98-
def to_proto(self) -> proto_rpc.RpcError:
116+
def _to_proto(self) -> proto_rpc.RpcError:
99117
return proto_rpc.RpcError(code=self.code, message=self.message, data=self.data)
100118

101119
@classmethod
102120
def _built_in(
103121
cls, code: "RpcError.ErrorCode", data: Optional[str] = None
104122
) -> "RpcError":
105-
"""
106-
Creates an error object from the ErrorCode, with an auto-populated message.
107-
"""
108123
message = cls.ErrorMessage[code]
109124
return cls(code, message, data)

0 commit comments

Comments
 (0)