better error message when using wrong forge-root-url

This commit is contained in:
crapStone 2024-05-19 23:52:46 +02:00
parent b54cd38d0b
commit 9ce901bfa0
No known key found for this signature in database
GPG key ID: 22D4BF0CF7CC29C8

View file

@ -57,12 +57,13 @@ type Client struct {
defaultMimeType string
}
func NewClient(cfg config.GiteaConfig, respCache cache.ICache) (*Client, error) {
rootURL, err := url.Parse(cfg.Root)
func NewClient(cfg config.ForgeConfig, respCache cache.ICache) (*Client, error) {
// url.Parse returns valid on almost anything...
rootURL, err := url.ParseRequestURI(cfg.Root)
if err != nil {
return nil, err
return nil, fmt.Errorf("invalid forgejo/gitea root url: %w", err)
}
giteaRoot := strings.Trim(rootURL.String(), "/")
giteaRoot := strings.TrimSuffix(rootURL.String(), "/")
stdClient := http.Client{Timeout: 10 * time.Second}