diff --git a/cns/client/client.go b/cns/client/client.go index f7e41fba23..d3fe3d9a94 100644 --- a/cns/client/client.go +++ b/cns/client/client.go @@ -47,8 +47,6 @@ var clientPaths = []string{ cns.GetHomeAz, } -var ErrAPINotFound error = errors.New("api not found") - type do interface { Do(*http.Request) (*http.Response, error) } @@ -403,16 +401,18 @@ func (c *Client) RequestIPs(ctx context.Context, ipconfig cns.IPConfigsRequest) req.Header.Set(headerContentType, contentTypeJSON) res, err := c.client.Do(req) - // if we get a 404 error - if res.StatusCode == http.StatusNotFound { - return nil, fmt.Errorf("cannot find API RequestIPs %w: %v", ErrAPINotFound, err) //nolint:errorlint // multiple %w not supported in 1.19 - } - if err != nil { return nil, errors.Wrap(err, "http request failed") } defer res.Body.Close() + if res.StatusCode == http.StatusNotFound { + return nil, &CNSClientError{ + Code: types.UnsupportedAPI, + Err: errors.Errorf("Unsupported API"), + } + } + if res.StatusCode != http.StatusOK { return nil, errors.Errorf("http response %d", res.StatusCode) } @@ -445,17 +445,19 @@ func (c *Client) ReleaseIPs(ctx context.Context, ipconfig cns.IPConfigsRequest) } req.Header.Set(headerContentType, contentTypeJSON) res, err := c.client.Do(req) - - // if we get a 404 error - if res.StatusCode == http.StatusNotFound { - return fmt.Errorf("cannot find API ReleaseIPs %w: %v", ErrAPINotFound, err) //nolint:errorlint // multiple %w not supported in 1.19 - } - if err != nil { return errors.Wrap(err, "http request failed") } defer res.Body.Close() + // if we get a 404 error + if res.StatusCode == http.StatusNotFound { + return &CNSClientError{ + Code: types.UnsupportedAPI, + Err: errors.Errorf("Unsupported API"), + } + } + if res.StatusCode != http.StatusOK { return errors.Errorf("http response %d", res.StatusCode) }