From e58955105a3a792f1cc90589b54dd6e48e29a6a9 Mon Sep 17 00:00:00 2001 From: Tsuzu <8574909+tsuzu@users.noreply.github.com> Date: Mon, 9 Dec 2024 03:12:57 +0900 Subject: [PATCH] Validate status code --- pkg/issuer/issuer.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pkg/issuer/issuer.go b/pkg/issuer/issuer.go index 33f9f04..59ae185 100644 --- a/pkg/issuer/issuer.go +++ b/pkg/issuer/issuer.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "io" "log/slog" "net/http" "os" @@ -54,6 +55,14 @@ func (iss *tokenIssuer) issue(ctx context.Context, config Config) (string, int, } defer resp.Body.Close() + if resp.StatusCode != http.StatusOK { + b, _ := io.ReadAll(resp.Body) + + slog.Error("failed to issue access token", "body", string(b)) + + return "", 0, fmt.Errorf("unexpected status code: %d", resp.StatusCode) + } + var token tokenResponse if err := json.NewDecoder(resp.Body).Decode(&token); err != nil { return "", 0, fmt.Errorf("failed to decode response: %w", err)