From ecc92b1e3e9267a79b4979fc916a7767ec78d10f Mon Sep 17 00:00:00 2001 From: Ash <159829404+hedge-sparrow@users.noreply.github.com> Date: Mon, 25 Nov 2024 15:04:38 +0000 Subject: [PATCH] [bug] Quick fix for handling non 200 status codes when loading specs from URI (#1695) * Quick fix for handling non 200 status codes when loading specs from URI Go http client already handles 3xx responses for us * note --- pkg/supportbundle/load.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pkg/supportbundle/load.go b/pkg/supportbundle/load.go index 888110cc0..7dd60cd7e 100644 --- a/pkg/supportbundle/load.go +++ b/pkg/supportbundle/load.go @@ -252,6 +252,14 @@ func loadSpecFromURL(arg string) ([]byte, error) { } return nil, errors.Wrap(err, "execute request") } + + // handle non 2xx http statuses + // redirects appear to already be handled by the go http client + // TODO: handle potential for redirect loops breaking this? + if resp.StatusCode != 200 { + return nil, errors.New("request returned non 200 response") + } + defer resp.Body.Close() body, err := io.ReadAll(resp.Body)