Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,18 @@ func (c *Client) TokenIsValid() (bool, error) {
}

// IsPingable calls the API /ping to determine whether the API can be reached.
func (c *Client) IsPingable() (bool, error) {
func (c *Client) IsPingable() error {
url := fmt.Sprintf("%s/ping", c.APIBaseURL)
req, err := c.NewRequest("GET", url, nil)
if err != nil {
return false, err
return err
}
resp, err := c.Do(req)
if err != nil {
return false, err
return err
}
return resp.StatusCode == http.StatusOK, nil
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("API returned %s", resp.Status)
}
return nil
}
3 changes: 1 addition & 2 deletions cmd/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ func runConfigure(configuration config.Configuration, flags *pflag.FlagSet) erro
return err
}

ok, err := client.IsPingable()
if !ok || err != nil {
if err := client.IsPingable(); err != nil {
return fmt.Errorf("The base API URL '%s' cannot be reached.\n\n%s", baseURL, err)
}
}
Expand Down