mirror of
https://github.com/zitadel/zitadel.git
synced 2025-04-16 01:01:30 +00:00
fix tracing/statusFromError
This commit is contained in:
parent
affd2da40a
commit
39039dde62
@ -11,14 +11,14 @@ func CaosToGRPCError(err error) error {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
code, msg, ok := extract(err)
|
code, msg, ok := Extract(err)
|
||||||
if !ok {
|
if !ok {
|
||||||
return status.Convert(err).Err()
|
return status.Convert(err).Err()
|
||||||
}
|
}
|
||||||
return status.Error(code, msg)
|
return status.Error(code, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func extract(err error) (c codes.Code, msg string, ok bool) {
|
func Extract(err error) (c codes.Code, msg string, ok bool) {
|
||||||
switch caosErr := err.(type) {
|
switch caosErr := err.(type) {
|
||||||
case *caos_errs.AlreadyExistsError:
|
case *caos_errs.AlreadyExistsError:
|
||||||
return codes.AlreadyExists, caosErr.GetMessage(), true
|
return codes.AlreadyExists, caosErr.GetMessage(), true
|
||||||
|
@ -5,9 +5,8 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"go.opencensus.io/trace"
|
"go.opencensus.io/trace"
|
||||||
"google.golang.org/grpc/codes"
|
|
||||||
"google.golang.org/grpc/status"
|
|
||||||
|
|
||||||
|
"github.com/caos/zitadel/internal/api/grpc"
|
||||||
"github.com/caos/zitadel/internal/errors"
|
"github.com/caos/zitadel/internal/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -41,10 +40,8 @@ func (s *Span) SetStatusByError(err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func statusFromError(err error) trace.Status {
|
func statusFromError(err error) trace.Status {
|
||||||
if statusErr, ok := status.FromError(err); ok {
|
code, msg, _ := grpc.Extract(err)
|
||||||
return trace.Status{Code: int32(statusErr.Code()), Message: statusErr.Message()}
|
return trace.Status{Code: int32(code), Message: msg}
|
||||||
}
|
|
||||||
return trace.Status{Code: int32(codes.Unknown), Message: "Unknown"}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddAnnotation creates an annotation. The annotation will not be added to the tracing use Annotate(msg) afterwards
|
// AddAnnotation creates an annotation. The annotation will not be added to the tracing use Annotate(msg) afterwards
|
||||||
|
Loading…
x
Reference in New Issue
Block a user