@@ -98,49 +98,20 @@ async def create_user(self, request: CreateUserRequest, ctx: RequestContext) ->
9898 )
9999```
100100
101- Reading error details on the client:
101+ Reading error details on the client - error details are ` google.protobuf.Any ` messages that can be unpacked to their original types :
102102
103103``` python
104104try :
105105 response = await client.some_method(request)
106106except ConnectError as e:
107107 for detail in e.details:
108- # Details are google.protobuf.Any messages
109- unpacked = Struct()
110- if detail.Unpack(unpacked):
111- print (f " Error detail: { unpacked} " )
112- ```
113-
114- ### Understanding google.protobuf.Any
115-
116- The ` google.protobuf.Any ` type stores arbitrary protobuf messages along with their type information:
117-
118- - ` type_url ` : A string identifying the message type (e.g., ` type.googleapis.com/google.protobuf.Struct ` )
119- - ` value ` : The serialized bytes of the actual message
120-
121- Debugging tips:
122-
123- ``` python
124- try :
125- response = await client.some_method(request)
126- except ConnectError as e:
127- for detail in e.details:
128- # Inspect the type URL
129- print (f " Detail type: { detail.type_url} " )
130-
131- # Check type before unpacking
108+ # Check the type before unpacking
132109 if detail.Is(Struct.DESCRIPTOR ):
133110 unpacked = Struct()
134111 detail.Unpack(unpacked)
135- print (f " Struct detail: { unpacked} " )
112+ print (f " Error detail: { unpacked} " )
136113```
137114
138- Common issues:
139-
140- 1 . ** Type mismatch** : If ` Unpack() ` returns ` False ` , check the ` type_url ` to see the actual type
141- 2 . ** Missing imports** : Import the protobuf message classes for the error details you expect
142- 3 . ** Custom details** : Ensure both client and server have access to the same proto definitions
143-
144115### Standard error detail types
145116
146117With ` googleapis-common-protos ` installed, you can use standard types like:
0 commit comments