@@ -272,23 +272,26 @@ def transcode(http_options, message=None, **request_kwargs):
272
272
ValueError: If the request does not match the given template.
273
273
"""
274
274
transcoded_value = message or request_kwargs
275
+ bindings = []
275
276
for http_option in http_options :
276
277
request = {}
277
278
278
279
# Assign path
279
280
uri_template = http_option ["uri" ]
280
- path_fields = [
281
- match .group ("name" ) for match in _VARIABLE_RE .finditer (uri_template )
281
+ fields = [
282
+ ( m .group ("name" ), m . group ( "template" )) for m in _VARIABLE_RE .finditer (uri_template )
282
283
]
283
- path_args = {field : get_field (transcoded_value , field ) for field in path_fields }
284
+ bindings .append ((uri_template , fields ))
285
+
286
+ path_args = {field : get_field (transcoded_value , field ) for field , _ in fields }
284
287
request ["uri" ] = expand (uri_template , ** path_args )
285
288
286
289
if not validate (uri_template , request ["uri" ]) or not all (path_args .values ()):
287
290
continue
288
291
289
292
# Remove fields used in uri path from request
290
293
leftovers = copy .deepcopy (transcoded_value )
291
- for path_field in path_fields :
294
+ for path_field , _ in fields :
292
295
delete_field (leftovers , path_field )
293
296
294
297
# Assign body and query params
@@ -316,8 +319,21 @@ def transcode(http_options, message=None, **request_kwargs):
316
319
request ["method" ] = http_option ["method" ]
317
320
return request
318
321
319
- raise ValueError (
320
- "Request {} does not match any URL path template in available HttpRule's {}" .format (
321
- request_kwargs , [opt ["uri" ] for opt in http_options ]
322
+ bindings_description = [
323
+ "\n \t URI: \" {}\" "
324
+ "\n \t Required request fields:\n \t \t {}" .format (
325
+ uri ,
326
+ "\n \t \t " .join (["field: \" {}\" , pattern: \" {}\" " .format (n , p if p else "*" ) for n , p in fields ])
322
327
)
328
+ for uri , fields in bindings
329
+ ]
330
+
331
+ raise ValueError (
332
+ "Invalid request."
333
+ "\n Some of the fields of the request message are either not initialized or "
334
+ "initialized with an invalid value."
335
+ "\n Please make sure your request matches at least one accepted HTTP binding."
336
+ "\n To match a binding the request message must have all the required fields "
337
+ "initialized with values matching their patterns as "
338
+ "listed below:{}" .format ("\n " .join (bindings_description ))
323
339
)
0 commit comments