Concepts
Error Handling
Structured errors from server to client.
Error Handling
pyRPC 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 pyrpc_core 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 (TypeScript)
Catch PyRPCError when calling procedures. The client ensures that server-side errors are caught and surfaced with their original codes and messages.
import { PyRPCError } from "@pyrpc/client";
try {
const user = await client.get_user(999);
} catch (e) {
if (e instanceof PyRPCError) {
console.error(e.code); // -404
console.error(e.message); // User not found
}
}Standard 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.