diff --git a/workspace-server/internal/handlers/github_token.go b/workspace-server/internal/handlers/github_token.go index ce9492a9d..eeb6a7ce7 100644 --- a/workspace-server/internal/handlers/github_token.go +++ b/workspace-server/internal/handlers/github_token.go @@ -159,11 +159,15 @@ func generateAppInstallationToken() (string, time.Time, error) { req, _ := http.NewRequest("POST", fmt.Sprintf("https://api.github.com/app/installations/%d/access_tokens", installID), nil) req.Header.Set("Authorization", "Bearer "+signed) req.Header.Set("Accept", "application/vnd.github+json") - resp, err := http.DefaultClient.Do(req) + client := &http.Client{Timeout: 15 * time.Second} + resp, err := client.Do(req) if err != nil { return "", time.Time{}, err } defer func() { _ = resp.Body.Close() }() + if resp.StatusCode < 200 || resp.StatusCode >= 300 { + return "", time.Time{}, fmt.Errorf("github API returned status %d", resp.StatusCode) + } var result struct { Token string `json:"token"` ExpiresAt time.Time `json:"expires_at"`