Concepts
Error Handling
Structured errors from server to client.
Error Handling
pRPC uses structured errors that flow from your procedures to the client. No opaque strings — codes and messages are predictable.
Server-Side
Raise RPCError in your procedures:
from prpc import rpc, RPCError
@rpc
def get_user(user_id: int) -> dict:
user = db.find_user(user_id)
if not user:
raise RPCError(-404, "User not found")
return userClient-Side
Catch RPCError when calling procedures:
from prpc import RPCClient, RPCError
with RPCClient("http://localhost:8000") as client:
try:
user = client.get_user(user_id=999)
except RPCError as e:
print(e.code) # -404
print(e.message) # User not foundStandard Codes
| Code | Meaning |
|---|---|
| -32600 | Invalid Request |
| -32601 | Method not found |
| -32602 | Invalid params |
| -32603 | Internal error |
Use negative codes (e.g. -404, -401) for application-specific errors.