Skip to content

Commit

Permalink
feat: handle no db results error
Browse files Browse the repository at this point in the history
  • Loading branch information
crlssn committed Jan 10, 2025
1 parent 292f275 commit 9a4fe31
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
2 changes: 1 addition & 1 deletion server/rpc/handlers/v1/exercise.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (h *exerciseHandler) GetExercise(ctx context.Context, req *connect.Request[
exercise, err := h.repo.GetExercise(ctx, repo.GetExerciseWithID(req.Msg.GetId()))
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
log.Error("exercise not found")
log.Warn("exercise not found")
return nil, connect.NewError(connect.CodeNotFound, nil)
}

Expand Down
2 changes: 1 addition & 1 deletion server/rpc/handlers/v1/routine.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (h *routineHandler) GetRoutine(ctx context.Context, req *connect.Request[ap
)
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
log.Error("routine not found", zap.Error(err))
log.Warn("routine not found", zap.Error(err))
return nil, connect.NewError(connect.CodeNotFound, nil)
}

Expand Down
46 changes: 46 additions & 0 deletions server/xzap/xzap_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package xzap_test

import (
"testing"

"github.com/stretchr/testify/require"
"go.uber.org/zap/zapcore"

"github.com/crlssn/getstronger/server/xzap"
)

func TestFields(t *testing.T) {
t.Parallel()

require.Equal(t, zapcore.Field{
Key: "rpc",
Type: zapcore.StringType,
Integer: 0,
String: "value",
Interface: nil,
}, xzap.FieldRPC("value"))

require.Equal(t, zapcore.Field{
Key: "user_id",
Type: zapcore.StringType,
Integer: 0,
String: "value",
Interface: nil,
}, xzap.FieldUserID("value"))

require.Equal(t, zapcore.Field{
Key: "routine_id",
Type: zapcore.StringType,
Integer: 0,
String: "value",
Interface: nil,
}, xzap.FiledRoutineID("value"))

require.Equal(t, zapcore.Field{
Key: "exercise_id",
Type: zapcore.StringType,
Integer: 0,
String: "value",
Interface: nil,
}, xzap.FieldExerciseID("value"))
}

0 comments on commit 9a4fe31

Please sign in to comment.