Skip to content

Commit 03f8b6b

Browse files
authored
feat(storage): local binding errors for bad requests (#2763)
1 parent 19577f6 commit 03f8b6b

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

internal/api/model.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414

1515
package api
1616

17-
import "slices"
17+
import (
18+
"slices"
19+
"strings"
20+
)
1821

1922
// Typez represent different field types that may be found in messages.
2023
type Typez int
@@ -344,6 +347,18 @@ type RoutingInfoVariant struct {
344347
Codec any
345348
}
346349

350+
func (v *RoutingInfoVariant) FieldName() string {
351+
return strings.Join(v.FieldPath, ".")
352+
}
353+
354+
func (v *RoutingInfoVariant) TemplateAsString() string {
355+
var full []string
356+
full = append(full, v.Prefix.Segments...)
357+
full = append(full, v.Matching.Segments...)
358+
full = append(full, v.Suffix.Segments...)
359+
return strings.Join(full, "/")
360+
}
361+
347362
type RoutingPathSpec struct {
348363
// A sequence of matching segments.
349364
//

internal/rust/templates/grpc-client/routinginfo.mustache

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,28 @@ let x_goog_request_params = {
3030
{{/Routing}}
3131
])
3232
};
33+
{{#Codec.RoutingRequired}}
34+
if x_goog_request_params.is_empty() {
35+
use gax::error::binding::BindingError;
36+
use gaxi::routing_parameter::Segment;
37+
use gaxi::path_parameter::PathMismatchBuilder;
38+
let mut paths = Vec::new();
39+
{{#Routing}}
40+
{{#Variants}}
41+
{
42+
let builder = PathMismatchBuilder::default().maybe_add(
43+
Some(&req){{#Codec.FieldAccessors}}{{{.}}}{{/Codec.FieldAccessors}},
44+
&[
45+
{{#Codec.PrefixSegments}}{{{.}}}, {{/Codec.PrefixSegments}}
46+
{{#Codec.MatchingSegments}}{{{.}}}, {{/Codec.MatchingSegments}}
47+
{{#Codec.SuffixSegments}}{{{.}}}, {{/Codec.SuffixSegments}}
48+
],
49+
"{{FieldName}}",
50+
"{{{TemplateAsString}}}");
51+
paths.push(builder.build());
52+
}
53+
{{/Variants}}
54+
{{/Routing}}
55+
return Err(gax::error::Error::binding(BindingError { paths }))
56+
}
57+
{{/Codec.RoutingRequired}}

0 commit comments

Comments
 (0)