fixup grpc error codes in unary and stream processing
All checks were successful
sync / sync (push) Successful in 26s
coverage / build (push) Successful in 1m51s
test / test (push) Successful in 2m40s

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
2025-06-08 11:16:34 +03:00
parent 20fb19fee9
commit 2b3c413adc

19
grpc.go
View File

@@ -404,7 +404,16 @@ func (g *Server) processRequest(ctx context.Context, stream grpc.ServerStream, s
} }
} }
if appErr != nil { if appErr != nil {
var err error
var errStatus *status.Status var errStatus *status.Status
var ok bool
errStatus, ok = status.FromError(appErr)
if ok {
return errStatus.Err()
}
if errStatus = status.FromContextError(appErr); errStatus.Code() != codes.Unknown {
return errStatus.Err()
}
switch verr := appErr.(type) { switch verr := appErr.(type) {
case *errors.Error: case *errors.Error:
statusCode = microError(verr) statusCode = microError(verr)
@@ -418,8 +427,6 @@ func (g *Server) processRequest(ctx context.Context, stream grpc.ServerStream, s
if err != nil { if err != nil {
return err return err
} }
case (interface{ GRPCStatus() *status.Status }):
errStatus = verr.GRPCStatus()
default: default:
g.mu.RLock() g.mu.RLock()
config := g.opts config := g.opts
@@ -490,6 +497,14 @@ func (g *Server) processStream(ctx context.Context, stream grpc.ServerStream, se
if appErr != nil { if appErr != nil {
var err error var err error
var errStatus *status.Status var errStatus *status.Status
var ok bool
errStatus, ok = status.FromError(appErr)
if ok {
return errStatus.Err()
}
if errStatus = status.FromContextError(appErr); errStatus.Code() != codes.Unknown {
return errStatus.Err()
}
switch verr := appErr.(type) { switch verr := appErr.(type) {
case *errors.Error: case *errors.Error:
statusCode = microError(verr) statusCode = microError(verr)