Skip to content

Commit

Permalink
chore: Streamline CDS client error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
rg0now committed Feb 2, 2024
1 parent d93e41c commit 00c9c0e
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions pkg/config/client/cds_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"fmt"
"net/http"
"strings"

stnrv1 "github.com/l7mp/stunner/pkg/apis/v1"
"github.com/l7mp/stunner/pkg/config/client/api"
Expand Down Expand Up @@ -85,7 +86,9 @@ func (a *AllConfigsAPI) Get(ctx context.Context) ([]*stnrv1.StunnerConfig, error
}

if r.HTTPResponse.StatusCode != http.StatusOK {
return []*stnrv1.StunnerConfig{}, fmt.Errorf("HTTP error: %s", r.HTTPResponse.Status)
body := strings.TrimSpace(string(r.Body))
return []*stnrv1.StunnerConfig{}, fmt.Errorf("HTTP error (status: %s): %s",
r.HTTPResponse.Status, body)
}

return decodeConfigList(r.Body)
Expand Down Expand Up @@ -148,8 +151,9 @@ func (a *ConfigsNamespaceAPI) Get(ctx context.Context) ([]*stnrv1.StunnerConfig,
}

if r.HTTPResponse.StatusCode != http.StatusOK {
return []*stnrv1.StunnerConfig{}, fmt.Errorf("HTTP error: %s",
r.HTTPResponse.Status)
body := strings.TrimSpace(string(r.Body))
return []*stnrv1.StunnerConfig{}, fmt.Errorf("HTTP error (status: %s): %s",
r.HTTPResponse.Status, body)
}

return decodeConfigList(r.Body)
Expand Down Expand Up @@ -215,8 +219,9 @@ func (a *ConfigNamespaceNameAPI) Get(ctx context.Context) ([]*stnrv1.StunnerConf
}

if r.HTTPResponse.StatusCode != http.StatusOK {
return []*stnrv1.StunnerConfig{}, fmt.Errorf("HTTP error: %s",
r.HTTPResponse.Status)
body := strings.TrimSpace(string(r.Body))
return []*stnrv1.StunnerConfig{}, fmt.Errorf("HTTP error (status: %s): %s",
r.HTTPResponse.Status, body)
}

return decodeConfig(r.Body)
Expand Down

0 comments on commit 00c9c0e

Please sign in to comment.