From 49b464fd4d6d130d2dacee67b97c21caaf980c0d Mon Sep 17 00:00:00 2001 From: Sylvain Rabot Date: Wed, 8 Dec 2021 14:27:11 +0100 Subject: [PATCH] Handle HTTP error codes in file loader GitHub release files like https://github.com/fluxcd/helm-controller/releases/download/v0.14.0/helm-controller.crds.yaml seems to be hosted on Azure and it seems that there are egress limits that can be reached, e.g.: ```xml ServerBusyEgress is over the account limit. RequestId:f4a46b38-001e-0046-2437-ec16e2000000 Time:2021-12-08T13:28:03.8542138Z ``` This patch allows to have a clear Error message instead of just `missing Resource metadata`: ``` Error: accumulating resources: accumulation err='accumulating resources from 'https://github.com/fluxcd/source-controller/releases/download/v0.19.0/source-controller.crds.yaml': URL returned error 503 (Service Unavailable)': evalsymlink failure on '/private/var/folders/hq/ttl6jyh539q55fz6282w0jyc0000gn/T/kustomize-3508224975/releases/download/v0.19.0/source-controller.crds.yaml' : lstat /private/var/folders/hq/ttl6jyh539q55fz6282w0jyc0000gn/T/kustomize-3508224975/releases: no such file or directory ``` Signed-off-by: Sylvain Rabot --- api/loader/fileloader.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/api/loader/fileloader.go b/api/loader/fileloader.go index 92bfc3f69..c2e7bb9e2 100644 --- a/api/loader/fileloader.go +++ b/api/loader/fileloader.go @@ -313,6 +313,9 @@ func (fl *fileLoader) Load(path string) ([]byte, error) { return nil, err } defer resp.Body.Close() + if resp.StatusCode < 200 || resp.StatusCode > 299 { + return nil, fmt.Errorf("URL returned error %d (%s)", resp.StatusCode, http.StatusText(resp.StatusCode)) + } body, err := ioutil.ReadAll(resp.Body) if err != nil { return nil, err