Skip to content

Commit

Permalink
add code
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanvc committed Jan 12, 2024
1 parent 06d654b commit 31ff12c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
3 changes: 2 additions & 1 deletion base/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ type statusError struct {
}

func (se *statusError) Error() string {
return se.s.GetMsg()
return fmt.Sprintf("code=%s|event=%s|msg=%s",
se.s.GetCode().String(), se.s.GetEvent(), se.s.GetMsg())
}

func (se *statusError) EvoStatus() *Status {
Expand Down
13 changes: 13 additions & 0 deletions base/status_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package base

import (
"errors"
"github.com/stretchr/testify/require"
"google.golang.org/grpc/codes"
"testing"
)

func Test_statusError_Error(t *testing.T) {
err := errors.Join(errors.New("hello"), New(codes.Internal, "").Err())
require.Equal(t, "hello\ncode=Internal|event=|msg=", err.Error())
}
3 changes: 0 additions & 3 deletions plog/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ func NamedError(k string, err error) slog.Attr {
if err == nil {
return slog.Any("err", nil)
}
if s, ok := base.FromError(err); ok {
return slog.Any(k, s)
}
return slog.String(k, err.Error())
}

Expand Down

0 comments on commit 31ff12c

Please sign in to comment.