Skip to content

Commit

Permalink
byz
Browse files Browse the repository at this point in the history
  • Loading branch information
bcherry committed Oct 8, 2024
1 parent 575d79c commit 775b199
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
19 changes: 8 additions & 11 deletions examples/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ async def main():
print("Error:", error)

try:
print("\n\nRunning math example...")
await perform_square_root(callers_room)
await asyncio.sleep(2)
await perform_quantum_hypergeometric_series(callers_room)
print("\n\nRunning error handling example...")
await perform_divide(callers_room)
except Exception as error:
print("Error:", error)

try:
print("\n\nRunning divide by zero example...")
await perform_divide(callers_room)
print("\n\nRunning math example...")
await perform_square_root(callers_room)
await asyncio.sleep(2)
await perform_quantum_hypergeometric_series(callers_room)
except Exception as error:
print("Error:", error)

Expand Down Expand Up @@ -99,9 +99,6 @@ async def divide_method(
divisor = json_data["divisor"]
print(f"[Math Genius] {caller.identity} wants to divide {dividend} by {divisor}.")

if divisor == 0:
raise ValueError("Cannot divide by zero!")

result = dividend / divisor
return json.dumps({"result": result})

Expand Down Expand Up @@ -159,7 +156,7 @@ async def perform_quantum_hypergeometric_series(room: rtc.Room):


async def perform_divide(room: rtc.Room):
print("[Caller] Let's try to divide by zero!")
print("[Caller] Let's divide 10 by 0.")
try:
response = await room.local_participant.perform_rpc(
"math-genius", "divide", json.dumps({"dividend": 10, "divisor": 0})
Expand All @@ -168,7 +165,7 @@ async def perform_divide(room: rtc.Room):
print(f"[Caller] The result is {parsed_response['result']}")
except rtc.RpcError as error:
if error.code == rtc.RpcError.ErrorCode.APPLICATION_ERROR:
print("[Caller] Aww something went wrong over there, too bad!")
print("[Caller] Aww something went wrong with that one, lets try something else.")
else:
print(f"[Caller] RPC call failed with unexpected RpcError: {error}")
except Exception as error:
Expand Down
2 changes: 1 addition & 1 deletion livekit-rtc/livekit/rtc/participant.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ async def _handle_rpc_method_invocation(
response_error = error
except Exception as error:
print(
f"Uncaught error returned by RPC handler for {method}. Returning UNCAUGHT_ERROR instead.",
f"Uncaught error returned by RPC handler for {method}. Returning APPLICATION_ERROR instead.",
error,
)
response_error = RpcError._built_in(RpcError.ErrorCode.APPLICATION_ERROR)
Expand Down
2 changes: 1 addition & 1 deletion livekit-rtc/rust-sdks

0 comments on commit 775b199

Please sign in to comment.