feat: more meaningful error messages, close body on httpc requests (#2238)
* feat: more meaningful error messages, close body on httpc requests * fix: test failure
This commit is contained in:
@@ -27,6 +27,8 @@ type (
|
||||
|
||||
// Upstream is the configuration for an upstream.
|
||||
Upstream struct {
|
||||
// Name is the name of the upstream.
|
||||
Name string `json:",optional"`
|
||||
// Grpc is the target of the upstream.
|
||||
Grpc zrpc.RpcClientConf
|
||||
// ProtoSets is the file list of proto set, like [hello.pb].
|
||||
|
||||
@@ -59,6 +59,10 @@ func (s *Server) Stop() {
|
||||
}
|
||||
|
||||
func (s *Server) build() error {
|
||||
if err := s.ensureUpstreamNames(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return mr.MapReduceVoid(func(source chan<- interface{}) {
|
||||
for _, up := range s.upstreams {
|
||||
source <- up
|
||||
@@ -68,13 +72,13 @@ func (s *Server) build() error {
|
||||
cli := zrpc.MustNewClient(up.Grpc)
|
||||
source, err := s.createDescriptorSource(cli, up)
|
||||
if err != nil {
|
||||
cancel(err)
|
||||
cancel(fmt.Errorf("%s: %w", up.Name, err))
|
||||
return
|
||||
}
|
||||
|
||||
methods, err := internal.GetMethods(source)
|
||||
if err != nil {
|
||||
cancel(err)
|
||||
cancel(fmt.Errorf("%s: %w", up.Name, err))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -95,7 +99,7 @@ func (s *Server) build() error {
|
||||
}
|
||||
for _, m := range up.Mappings {
|
||||
if _, ok := methodSet[m.RpcPath]; !ok {
|
||||
cancel(fmt.Errorf("rpc method %s not found", m.RpcPath))
|
||||
cancel(fmt.Errorf("%s: rpc method %s not found", up.Name, m.RpcPath))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -162,6 +166,19 @@ func (s *Server) createDescriptorSource(cli zrpc.Client, up Upstream) (grpcurl.D
|
||||
return source, nil
|
||||
}
|
||||
|
||||
func (s *Server) ensureUpstreamNames() error {
|
||||
for _, up := range s.upstreams {
|
||||
target, err := up.Grpc.BuildTarget()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
up.Name = target
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Server) prepareMetadata(header http.Header) []string {
|
||||
vals := internal.ProcessHeaders(header)
|
||||
if s.processHeader != nil {
|
||||
|
||||
Reference in New Issue
Block a user