This commit is contained in:
2026-10-11 03:05:26 +07:00
parent 72ecdc0687
commit b733efe8e2
7 changed files with 96 additions and 6 deletions
+3
View File
@@ -16,5 +16,8 @@ func gameplayErrorStatus(err error, internalMessage string) error {
if errors.Is(err, gameplay_service.ErrGameNotFound) {
return status.Error(codes.NotFound, gameplay_service.ErrGameNotFound.Error())
}
if errors.Is(err, gameplay_service.ErrMovesNotAllowed) {
return status.Error(codes.FailedPrecondition, gameplay_service.ErrMovesNotAllowed.Error())
}
return status.Error(codes.Internal, internalMessage)
}
+22
View File
@@ -0,0 +1,22 @@
package app
import (
"errors"
"fmt"
"testing"
"evening_detective_server/internal/services/gameplay_service"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
func TestGameplayMoveErrorIsSafe(t *testing.T) {
mapped := gameplayErrorStatus(fmt.Errorf("private detail: %w", gameplay_service.ErrMovesNotAllowed), "не удалось сделать ход")
if status.Code(mapped) != codes.FailedPrecondition || status.Convert(mapped).Message() != gameplay_service.ErrMovesNotAllowed.Error() {
t.Fatalf("unexpected move error: %v", mapped)
}
mapped = gameplayErrorStatus(errors.New("private database detail"), "не удалось сделать ход")
if status.Code(mapped) != codes.Internal || status.Convert(mapped).Message() != "не удалось сделать ход" {
t.Fatalf("unsafe internal error: %v", mapped)
}
}