Skip to content

Commit 13e6181

Browse files
author
Katrina Owen
authored
Merge pull request #679 from exercism/api-error-configure-cmd
Improve the API ping in configure command
2 parents ea7d503 + 239f303 commit 13e6181

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

api/client.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,18 @@ func (c *Client) TokenIsValid() (bool, error) {
8787
}
8888

8989
// IsPingable calls the API /ping to determine whether the API can be reached.
90-
func (c *Client) IsPingable() (bool, error) {
90+
func (c *Client) IsPingable() error {
9191
url := fmt.Sprintf("%s/ping", c.APIBaseURL)
9292
req, err := c.NewRequest("GET", url, nil)
9393
if err != nil {
94-
return false, err
94+
return err
9595
}
9696
resp, err := c.Do(req)
9797
if err != nil {
98-
return false, err
98+
return err
9999
}
100-
return resp.StatusCode == http.StatusOK, nil
100+
if resp.StatusCode != http.StatusOK {
101+
return fmt.Errorf("API returned %s", resp.Status)
102+
}
103+
return nil
101104
}

cmd/configure.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ func runConfigure(configuration config.Configuration, flags *pflag.FlagSet) erro
9191
return err
9292
}
9393

94-
ok, err := client.IsPingable()
95-
if !ok || err != nil {
94+
if err := client.IsPingable(); err != nil {
9695
return fmt.Errorf("The base API URL '%s' cannot be reached.\n\n%s", baseURL, err)
9796
}
9897
}

0 commit comments

Comments
 (0)