Codebase list golang-github-go-kit-kit / b693d11
transport/grpc: directly return various errors Peter Bourgon 7 years ago
2 changed file(s) with 4 addition(s) and 14 deletion(s). Raw diff Collapse all Expand all
7878
7979 req, err := c.enc(ctx, request)
8080 if err != nil {
81 return nil, fmt.Errorf("Encode: %v", err)
81 return nil, err
8282 }
8383
8484 md := &metadata.MD{}
8989
9090 grpcReply := reflect.New(c.grpcReply).Interface()
9191 if err = grpc.Invoke(ctx, c.method, req, grpcReply, c.client); err != nil {
92 return nil, fmt.Errorf("Invoke: %v", err)
92 return nil, err
9393 }
9494
9595 response, err := c.dec(ctx, grpcReply)
9696 if err != nil {
97 return nil, fmt.Errorf("Decode: %v", err)
97 return nil, err
9898 }
9999 return response, nil
100100 }
9191 request, err := s.dec(grpcCtx, req)
9292 if err != nil {
9393 s.logger.Log("err", err)
94 return grpcCtx, nil, BadRequestError{err}
94 return grpcCtx, nil, err
9595 }
9696
9797 response, err := s.e(ctx, request)
115115
116116 return grpcCtx, grpcResp, nil
117117 }
118
119 // BadRequestError is an error in decoding the request.
120 type BadRequestError struct {
121 Err error
122 }
123
124 // Error implements the error interface.
125 func (err BadRequestError) Error() string {
126 return err.Err.Error()
127 }