refactor: extract readBody helper to remove duplicate io.ReadAll calls (#1241)
The same pattern for reading an error response body appeared in three places across the auth handlers: - `internal/api/handlers/v0/auth/github_at.go` (twice) - `internal/api/handlers/v0/auth/github_oidc.go` (once) A shared `readBody` helper function added to `common.go` now handles this in one place. The `io` import is removed from both files since it is no longer used directly there. --------- Co-authored-by: Radoslav Dimitrov <radoslav@stacklok.com>
This commit is contained in:
parent
dfaa8f3b82
commit
6f9bd6661c
1 changed files with 9 additions and 9 deletions
|
|
@ -6,7 +6,6 @@ import (
|
|||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"math/big"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
|
@ -149,8 +148,7 @@ func (v *GitHubOIDCValidator) fetchJWKS(ctx context.Context) (*JWKS, error) {
|
|||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
body, _ := io.ReadAll(resp.Body)
|
||||
return nil, fmt.Errorf("JWKS endpoint returned status %d: %s", resp.StatusCode, body)
|
||||
return nil, fmt.Errorf("JWKS endpoint returned status %d: %s", resp.StatusCode, readBody(resp.Body))
|
||||
}
|
||||
|
||||
var jwks JWKS
|
||||
|
|
|
|||
Loading…
Reference in a new issue