Skip to content

Commit

Permalink
Validate status code
Browse files Browse the repository at this point in the history
  • Loading branch information
tsuzu committed Dec 8, 2024
1 parent 7aeb4e0 commit e589551
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/issuer/issuer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"io"
"log/slog"
"net/http"
"os"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit e589551

Please sign in to comment.