Skip to content

Commit

Permalink
adjust status to istatus
Browse files Browse the repository at this point in the history
  • Loading branch information
DMwangnima committed Nov 21, 2024
1 parent 2545c43 commit 9d514fa
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions pkg/remote/trans/nphttp2/grpc/http_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ import (
spb "google.golang.org/genproto/googleapis/rpc/status"
"google.golang.org/protobuf/proto"

istatus "github.com/cloudwego/kitex/internal/remote/trans/grpc/status"
"github.com/cloudwego/kitex/pkg/kerrors"
"github.com/cloudwego/kitex/pkg/klog"
"github.com/cloudwego/kitex/pkg/remote/trans/nphttp2/codes"
"github.com/cloudwego/kitex/pkg/remote/trans/nphttp2/grpc/grpcframe"
"github.com/cloudwego/kitex/pkg/remote/trans/nphttp2/status"
"github.com/cloudwego/kitex/pkg/utils"
)

Expand Down Expand Up @@ -111,8 +111,8 @@ type parsedHeaderData struct {
acceptEncoding string
// statusGen caches the stream status received from the trailer the server
// sent. Client side only. Do not access directly. After all trailers are
// parsed, use the status method to retrieve the status.
statusGen *status.Status
// parsed, use the status method to retrieve the istatus.
statusGen *istatus.Status
bizStatusErr kerrors.BizStatusErrorIface
// rawStatusCode and rawStatusMsg are set from the raw trailer fields and are not
// intended for direct access outside of parsing.
Expand Down Expand Up @@ -141,8 +141,8 @@ type parsedHeaderData struct {
// Otherwise (i.e. a content-type string starts without "application/grpc", or does not exist), we
// are in HTTP fallback mode, and should handle error specific to HTTP.
isGRPC bool
grpcStatus *status.Status
httpErrStatus *status.Status
grpcStatus *istatus.Status
httpErrStatus *istatus.Status
contentTypeErr string
}

Expand Down Expand Up @@ -233,10 +233,10 @@ func contentType(contentSubtype string) string {
return baseContentType + "+" + contentSubtype
}

func (d *decodeState) status() *status.Status {
func (d *decodeState) status() *istatus.Status {
if d.data.statusGen == nil {
// No status-details were provided; generate status using code/msg.
d.data.statusGen = status.New(codes.Code(safeCastInt32(*(d.data.rawStatusCode))), d.data.rawStatusMsg)
d.data.statusGen = istatus.New(codes.Code(safeCastInt32(*(d.data.rawStatusCode))), d.data.rawStatusMsg)
}
return d.data.statusGen
}
Expand Down Expand Up @@ -289,11 +289,11 @@ func decodeMetadataHeader(k, v string) (string, error) {
return v, nil
}

func (d *decodeState) decodeHeader(frame *grpcframe.MetaHeadersFrame) *status.Status {
func (d *decodeState) decodeHeader(frame *grpcframe.MetaHeadersFrame) *istatus.Status {
// frame.Truncated is set to true when framer detects that the current header
// list size hits MaxHeaderListSize limit.
if frame.Truncated {
return status.New(codes.Internal, "peer header list size exceeded limit")
return istatus.New(codes.Internal, "peer header list size exceeded limit")
}

for _, hf := range frame.Fields {
Expand Down Expand Up @@ -337,7 +337,7 @@ func (d *decodeState) decodeHeader(frame *grpcframe.MetaHeadersFrame) *status.St
}
}

return status.New(code, d.constructHTTPErrMsg())
return istatus.New(code, d.constructHTTPErrMsg())
}

// constructErrMsg constructs error message to be returned in HTTP fallback mode.
Expand Down Expand Up @@ -389,7 +389,7 @@ func (d *decodeState) processHeaderField(f hpack.HeaderField) {
case "grpc-status":
code, err := strconv.Atoi(f.Value)
if err != nil {
d.data.grpcStatus = status.Newf(codes.Internal, "transport: malformed grpc-status: %v", err)
d.data.grpcStatus = istatus.Newf(codes.Internal, "transport: malformed grpc-status: %v", err)
return
}
d.data.rawStatusCode = &code
Expand All @@ -398,56 +398,56 @@ func (d *decodeState) processHeaderField(f hpack.HeaderField) {
case "biz-status":
code, err := strconv.Atoi(f.Value)
if err != nil {
d.data.grpcStatus = status.Newf(codes.Internal, "transport: malformed biz-status: %v", err)
d.data.grpcStatus = istatus.Newf(codes.Internal, "transport: malformed biz-status: %v", err)
return
}
d.data.bizStatusCode = &code
case "biz-extra":
extra, err := utils.JSONStr2Map(f.Value)
if err != nil {
d.data.grpcStatus = status.Newf(codes.Internal, "transport: malformed biz-extra: %v", err)
d.data.grpcStatus = istatus.Newf(codes.Internal, "transport: malformed biz-extra: %v", err)
return
}
d.data.bizStatusExtra = extra
case "grpc-status-details-bin":
v, err := decodeBinHeader(f.Value)
if err != nil {
d.data.grpcStatus = status.Newf(codes.Internal, "transport: malformed grpc-status-details-bin: %v", err)
d.data.grpcStatus = istatus.Newf(codes.Internal, "transport: malformed grpc-status-details-bin: %v", err)
return
}
s := &spb.Status{}
if err := proto.Unmarshal(v, s); err != nil {
d.data.grpcStatus = status.Newf(codes.Internal, "transport: malformed grpc-status-details-bin: %v", err)
d.data.grpcStatus = istatus.Newf(codes.Internal, "transport: malformed grpc-status-details-bin: %v", err)
return
}
d.data.statusGen = status.FromProto(s)
d.data.statusGen = istatus.FromProto(s)
case "grpc-timeout":
d.data.timeoutSet = true
var err error
if d.data.timeout, err = decodeTimeout(f.Value); err != nil {
d.data.grpcStatus = status.Newf(codes.Internal, "transport: malformed time-out: %v", err)
d.data.grpcStatus = istatus.Newf(codes.Internal, "transport: malformed time-out: %v", err)
}
case ":path":
d.data.method = f.Value
case ":status":
code, err := strconv.Atoi(f.Value)
if err != nil {
d.data.httpErrStatus = status.Newf(codes.Internal, "transport: malformed http-status: %v", err)
d.data.httpErrStatus = istatus.Newf(codes.Internal, "transport: malformed http-status: %v", err)
return
}
d.data.httpStatus = &code
case "grpc-tags-bin":
v, err := decodeBinHeader(f.Value)
if err != nil {
d.data.grpcStatus = status.Newf(codes.Internal, "transport: malformed grpc-tags-bin: %v", err)
d.data.grpcStatus = istatus.Newf(codes.Internal, "transport: malformed grpc-tags-bin: %v", err)
return
}
d.data.statsTags = v
d.addMetadata(f.Name, string(v))
case "grpc-trace-bin":
v, err := decodeBinHeader(f.Value)
if err != nil {
d.data.grpcStatus = status.Newf(codes.Internal, "transport: malformed grpc-trace-bin: %v", err)
d.data.grpcStatus = istatus.Newf(codes.Internal, "transport: malformed grpc-trace-bin: %v", err)
return
}
d.data.statsTrace = v
Expand Down

0 comments on commit 9d514fa

Please sign in to comment.