From 039e58ccc1b6ebee3a78eba6d138cd4346527228 Mon Sep 17 00:00:00 2001 From: Anderson Queiroz Date: Fri, 1 Nov 2024 11:19:52 +0100 Subject: [PATCH] check HTTP status code --- kibana/fleet.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/kibana/fleet.go b/kibana/fleet.go index 8efa1da..e482035 100644 --- a/kibana/fleet.go +++ b/kibana/fleet.go @@ -519,6 +519,9 @@ func (client *Client) CreateFleetServerHosts(ctx context.Context, req ListFleetS return FleetServerHostsResponse{}, fmt.Errorf("error calling new fleet server hosts API: %w", err) } defer resp.Body.Close() + if resp.StatusCode != http.StatusOK { + return FleetServerHostsResponse{}, fmt.Errorf("error creating fleet-server host: unexpected status code: %s", r.Status) + } body, err := io.ReadAll(resp.Body) if err != nil { @@ -695,6 +698,9 @@ func (client *Client) CreateFleetProxy(ctx context.Context, req ProxiesRequest) return ProxiesResponse{}, err } defer r.Body.Close() + if r.StatusCode != http.StatusOK { + return ProxiesResponse{}, fmt.Errorf("error creating proxy: unexpected status code: %s", r.Status) + } resp := ProxiesResponse{} err = readJSONResponse(r, &resp)