@@ -9,6 +9,10 @@ Connect handlers raise errors using `ConnectError`:
99=== "ASGI"
1010
1111 ```python
12+ from connectrpc.code import Code
13+ from connectrpc.errors import ConnectError
14+ from connectrpc.request import RequestContext
15+
1216 async def greet(self, request: GreetRequest, ctx: RequestContext) -> GreetResponse:
1317 if not request.name:
1418 raise ConnectError(Code.INVALID_ARGUMENT, "name is required")
@@ -18,6 +22,10 @@ Connect handlers raise errors using `ConnectError`:
1822=== "WSGI"
1923
2024 ```python
25+ from connectrpc.code import Code
26+ from connectrpc.errors import ConnectError
27+ from connectrpc.request import RequestContext
28+
2129 def greet(self, request: GreetRequest, ctx: RequestContext) -> GreetResponse:
2230 if not request.name:
2331 raise ConnectError(Code.INVALID_ARGUMENT, "name is required")
@@ -29,6 +37,9 @@ Clients catch errors the same way:
2937=== "Async"
3038
3139 ```python
40+ from connectrpc.code import Code
41+ from connectrpc.errors import ConnectError
42+
3243 async with GreetServiceClient("http://localhost:8000") as client:
3344 try:
3445 response = await client.greet(GreetRequest(name=""))
@@ -42,6 +53,9 @@ Clients catch errors the same way:
4253=== "Sync"
4354
4455 ```python
56+ from connectrpc.code import Code
57+ from connectrpc.errors import ConnectError
58+
4559 with GreetServiceClientSync("http://localhost:8000") as client:
4660 try:
4761 response = client.greet(GreetRequest(name=""))
@@ -82,6 +96,9 @@ except ConnectError as e:
8296Errors can include strongly-typed details using protobuf messages:
8397
8498``` python
99+ from connectrpc.code import Code
100+ from connectrpc.errors import ConnectError
101+ from connectrpc.request import RequestContext
85102from google.protobuf.struct_pb2 import Struct, Value
86103
87104async def create_user (self , request : CreateUserRequest, ctx : RequestContext) -> CreateUserResponse:
@@ -96,9 +113,12 @@ async def create_user(self, request: CreateUserRequest, ctx: RequestContext) ->
96113 " Invalid user request" ,
97114 details = [error_detail]
98115 )
116+ # ... rest of implementation
99117```
100118
101- Reading error details on the client - error details are ` google.protobuf.Any ` messages that can be unpacked to their original types:
119+ ### Reading error details on the client
120+
121+ Error details are ` google.protobuf.Any ` messages that can be unpacked to their original types:
102122
103123``` python
104124try :
@@ -159,6 +179,11 @@ Content-Type: application/json
159179}
160180```
161181
182+ The ` details ` array contains error detail messages, where each entry has:
183+
184+ - ` type ` : The fully-qualified protobuf message type (e.g., ` google.protobuf.Struct ` )
185+ - ` value ` : The protobuf message serialized in binary format and then base64-encoded
186+
162187## See also
163188
164189- [ Interceptors] ( interceptors.md ) for error transformation and logging
0 commit comments