@@ -193,34 +193,56 @@ void phongo_throw_exception(php_phongo_error_domain_t domain, const char* format
193
193
va_end (args );
194
194
}
195
195
196
+ static int phongo_exception_append_error_labels (zval * labels , const bson_iter_t * iter )
197
+ {
198
+ bson_iter_t error_labels ;
199
+ uint32_t label_count = 0 ;
200
+
201
+ bson_iter_recurse (iter , & error_labels );
202
+ while (bson_iter_next (& error_labels )) {
203
+ if (BSON_ITER_HOLDS_UTF8 (& error_labels )) {
204
+ const char * error_label ;
205
+ uint32_t error_label_len ;
206
+
207
+ error_label = bson_iter_utf8 (& error_labels , & error_label_len );
208
+ ADD_NEXT_INDEX_STRINGL (labels , error_label , error_label_len );
209
+ label_count ++ ;
210
+ }
211
+ }
212
+
213
+ return label_count ;
214
+ }
215
+
196
216
static void phongo_exception_add_error_labels (const bson_t * reply )
197
217
{
198
218
bson_iter_t iter ;
219
+ zval labels ;
220
+ uint32_t label_count = 0 ;
199
221
200
222
if (!reply ) {
201
223
return ;
202
224
}
203
225
204
- if (bson_iter_init_find (& iter , reply , "errorLabels" )) {
205
- bson_iter_t error_labels ;
206
- zval labels ;
226
+ array_init (& labels );
207
227
208
- array_init (& labels );
228
+ if (bson_iter_init_find (& iter , reply , "errorLabels" )) {
229
+ label_count += phongo_exception_append_error_labels (& labels , & iter );
230
+ }
209
231
210
- bson_iter_recurse (& iter , & error_labels );
211
- while (bson_iter_next (& error_labels )) {
212
- if (BSON_ITER_HOLDS_UTF8 (& error_labels )) {
213
- const char * error_label ;
214
- uint32_t error_label_len ;
232
+ if (bson_iter_init_find (& iter , reply , "writeConcernError" )) {
233
+ bson_iter_t write_concern_error_iter ;
215
234
216
- error_label = bson_iter_utf8 ( & error_labels , & error_label_len );
217
- ADD_NEXT_INDEX_STRINGL ( & labels , error_label , error_label_len );
218
- }
235
+ bson_iter_recurse ( & iter , & write_concern_error_iter );
236
+ if ( bson_iter_find ( & write_concern_error_iter , "errorLabels" )) {
237
+ label_count += phongo_exception_append_error_labels ( & labels , & write_concern_error_iter );
219
238
}
239
+ }
220
240
241
+ if (label_count > 0 ) {
221
242
phongo_add_exception_prop (ZEND_STRL ("errorLabels" ), & labels );
222
- zval_ptr_dtor (& labels );
223
243
}
244
+
245
+ zval_ptr_dtor (& labels );
224
246
}
225
247
226
248
void phongo_throw_exception_from_bson_error_t_and_reply (bson_error_t * error , const bson_t * reply )
0 commit comments