Skip to content

Commit

Permalink
chore: fix log messages
Browse files Browse the repository at this point in the history
Signed-off-by: Bence Csati <[email protected]>

chore: fix log messages

Signed-off-by: Bence Csati <[email protected]>
  • Loading branch information
csatib02 committed Sep 8, 2024
1 parent 14d9922 commit 9c6358b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ linters-settings:
- default
- prefix(github.com/csatib02/kube-pod-autocomplete)
goimports:
local-prefixes: github.com/bank-vaults/kube-pod-autocomplete
local-prefixes: github.com/csatib02/kube-pod-autocomplete
misspell:
locale: US
nolintlint:
Expand Down
6 changes: 3 additions & 3 deletions internal/handlers/autocomplete.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func AutocompleteHandler(c *gin.Context) {
// var req model.AutoCompleteRequest
// if err := c.ShouldBindJSON(&req); err != nil {
// slog.Error(fmt.Errorf("failed to bind request: %w", err).Error())
// http.HandleHTTPError(c, errors.New("failed to bind request"))
// http.HandleHTTPError(c, http.StatusBadRequest, errors.New("failed to bind request"))
// return
// }

Expand Down Expand Up @@ -59,14 +59,14 @@ func AutocompleteHandler(c *gin.Context) {
service, err := autocomplete.NewAutoCompleteService()
if err != nil {
slog.Error(fmt.Errorf("failed to create autocomplete service: %w", err).Error())
httperror.HandleHTTPError(c, http.StatusBadRequest, err)
httperror.HandleHTTPError(c, http.StatusInternalServerError, err)
return
}

suggestions, err := service.GetAutocompleteSuggestions(c, req)
if err != nil {
slog.Error(fmt.Errorf("failed to get autocomplete suggestions: %w", err).Error())
httperror.HandleHTTPError(c, http.StatusBadRequest, err)
httperror.HandleHTTPError(c, http.StatusInternalServerError, err)
return
}

Expand Down
5 changes: 3 additions & 2 deletions internal/k8s/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package k8s

import (
"context"
"errors"
"fmt"

v1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -35,7 +36,7 @@ func (c *Client) ListResource(ctx context.Context, resource common.Resources) (c
case common.ResourceType:
return c.listPods(ctx)
default:
return nil, fmt.Errorf("unsupported resource type")
return nil, fmt.Errorf("unsupported resource type: %T", resource)
}
}

Expand All @@ -47,7 +48,7 @@ func (c *Client) listPods(ctx context.Context) (*v1.PodList, error) {

// Validate whether there are any pods in the cluster
if pods == nil {
return nil, fmt.Errorf("failed to list pods: no pods found")
return nil, errors.New("no pods found in the cluster")
}

return pods, nil
Expand Down
2 changes: 1 addition & 1 deletion internal/services/autocomplete/autocomplete.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (s *Service) GetAutocompleteSuggestions(ctx context.Context, req model.Auto

resources, err := s.k8sClient.ListResource(ctx, req.ResourceType)
if err != nil {
return nil, fmt.Errorf("failed to list pods: %w", err)
return nil, fmt.Errorf("failed to list resources: %w", err)
}

return s.extractSuggestions(resources, filters)
Expand Down

0 comments on commit 9c6358b

Please sign in to comment.