@@ -96,6 +96,11 @@ def __str__(self) -> str:
96
96
return self .summary ()
97
97
98
98
def summary (self ) -> str :
99
+ """
100
+ Determine a string succinct description of this error descriptor.
101
+
102
+ The precise format of this summary is determined by which fields are set.
103
+ """
99
104
non_code_part : str | None
100
105
if self .title :
101
106
if self .message :
@@ -141,6 +146,16 @@ class DataAPIDetailedErrorDescriptor:
141
146
command : dict [str , Any ] | None
142
147
raw_response : dict [str , Any ]
143
148
149
+ def __repr__ (self ) -> str :
150
+ pieces = [
151
+ f"error_descriptors={ self .error_descriptors .__repr__ ()} "
152
+ if self .error_descriptors
153
+ else None ,
154
+ "command=..." if self .command else None ,
155
+ "raw_response=..." if self .raw_response else None ,
156
+ ]
157
+ return f"{ self .__class__ .__name__ } ({ ', ' .join (pc for pc in pieces if pc )} )"
158
+
144
159
145
160
@dataclass
146
161
class DataAPIResponseException (DataAPIException ):
@@ -156,31 +171,35 @@ class DataAPIResponseException(DataAPIException):
156
171
157
172
Attributes:
158
173
text: a text message about the exception.
159
- error_descriptors: a list of all DataAPIErrorDescriptor objects
160
- found across all requests involved in this exception, which are
161
- possibly more than one.
162
174
detailed_error_descriptors: a list of DataAPIDetailedErrorDescriptor
163
175
objects, one for each of the requests performed during this operation.
164
176
For single-request methods, such as insert_one, this list always
165
177
has a single element.
166
178
"""
167
179
168
180
text : str | None
169
- error_descriptors : list [DataAPIErrorDescriptor ]
170
181
detailed_error_descriptors : list [DataAPIDetailedErrorDescriptor ]
171
182
172
183
def __init__ (
173
184
self ,
174
185
text : str | None ,
175
186
* ,
176
- error_descriptors : list [DataAPIErrorDescriptor ],
177
187
detailed_error_descriptors : list [DataAPIDetailedErrorDescriptor ],
178
188
) -> None :
179
189
super ().__init__ (text )
180
190
self .text = text
181
- self .error_descriptors = error_descriptors
182
191
self .detailed_error_descriptors = detailed_error_descriptors
183
192
193
+ @property
194
+ def error_descriptors (self ) -> list [DataAPIErrorDescriptor ]:
195
+ """Return a flattened list of all individual DataAPIErrorDescriptor objects."""
196
+
197
+ return [
198
+ error_descriptor
199
+ for d_e_d in self .detailed_error_descriptors
200
+ for error_descriptor in d_e_d .error_descriptors
201
+ ]
202
+
184
203
@classmethod
185
204
def from_response (
186
205
cls ,
@@ -219,15 +238,14 @@ def from_responses(
219
238
)
220
239
detailed_error_descriptors .append (detailed_error_descriptor )
221
240
222
- # flatten
223
- error_descriptors = [
241
+ flat_error_descriptors = [
224
242
error_descriptor
225
243
for d_e_d in detailed_error_descriptors
226
244
for error_descriptor in d_e_d .error_descriptors
227
245
]
228
246
229
- if error_descriptors :
230
- summaries = [e_d .summary () for e_d in error_descriptors ]
247
+ if flat_error_descriptors :
248
+ summaries = [e_d .summary () for e_d in flat_error_descriptors ]
231
249
if len (summaries ) == 1 :
232
250
text = summaries [0 ]
233
251
else :
@@ -241,7 +259,6 @@ def from_responses(
241
259
242
260
return cls (
243
261
text ,
244
- error_descriptors = error_descriptors ,
245
262
detailed_error_descriptors = detailed_error_descriptors ,
246
263
** kwargs ,
247
264
)
@@ -251,7 +268,6 @@ def data_api_response_exception(self) -> DataAPIResponseException:
251
268
252
269
return DataAPIResponseException (
253
270
text = self .text ,
254
- error_descriptors = self .error_descriptors ,
255
271
detailed_error_descriptors = self .detailed_error_descriptors ,
256
272
)
257
273
0 commit comments