@@ -272,23 +272,27 @@ def transcode(http_options, message=None, **request_kwargs):
272272 ValueError: If the request does not match the given template.
273273 """
274274 transcoded_value = message or request_kwargs
275+ bindings = []
275276 for http_option in http_options :
276277 request = {}
277278
278279 # Assign path
279280 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" ))
283+ for m in _VARIABLE_RE .finditer (uri_template )
282284 ]
283- path_args = {field : get_field (transcoded_value , field ) for field in path_fields }
285+ bindings .append ((uri_template , fields ))
286+
287+ path_args = {field : get_field (transcoded_value , field ) for field , _ in fields }
284288 request ["uri" ] = expand (uri_template , ** path_args )
285289
286290 if not validate (uri_template , request ["uri" ]) or not all (path_args .values ()):
287291 continue
288292
289293 # Remove fields used in uri path from request
290294 leftovers = copy .deepcopy (transcoded_value )
291- for path_field in path_fields :
295+ for path_field , _ in fields :
292296 delete_field (leftovers , path_field )
293297
294298 # Assign body and query params
@@ -316,8 +320,27 @@ def transcode(http_options, message=None, **request_kwargs):
316320 request ["method" ] = http_option ["method" ]
317321 return request
318322
323+ bindings_description = [
324+ '\n \t URI: "{}"'
325+ "\n \t Required request fields:\n \t \t {}" .format (
326+ uri ,
327+ "\n \t \t " .join (
328+ [
329+ 'field: "{}", pattern: "{}"' .format (n , p if p else "*" )
330+ for n , p in fields
331+ ]
332+ ),
333+ )
334+ for uri , fields in bindings
335+ ]
336+
319337 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 ]
338+ "Invalid request."
339+ "\n Some of the fields of the request message are either not initialized or "
340+ "initialized with an invalid value."
341+ "\n Please make sure your request matches at least one accepted HTTP binding."
342+ "\n To match a binding the request message must have all the required fields "
343+ "initialized with values matching their patterns as listed below:{}" .format (
344+ "\n " .join (bindings_description )
322345 )
323346 )
0 commit comments