diff --git a/x-pack/heartbeat/monitors/browser/source/zipurl.go b/x-pack/heartbeat/monitors/browser/source/zipurl.go index acd1db76821..400bf258910 100644 --- a/x-pack/heartbeat/monitors/browser/source/zipurl.go +++ b/x-pack/heartbeat/monitors/browser/source/zipurl.go @@ -174,7 +174,7 @@ func retryingZipRequest(method string, z *ZipURLSource) (resp *http.Response, er } time.Sleep(time.Second) } - if resp.StatusCode > 300 { + if resp != nil && resp.StatusCode > 300 { return nil, fmt.Errorf("failed to retrieve zip, received status of %d requesting zip URL", resp.StatusCode) } return resp, err diff --git a/x-pack/heartbeat/monitors/browser/source/zipurl_test.go b/x-pack/heartbeat/monitors/browser/source/zipurl_test.go index 7e0d7380114..93605aba11b 100644 --- a/x-pack/heartbeat/monitors/browser/source/zipurl_test.go +++ b/x-pack/heartbeat/monitors/browser/source/zipurl_test.go @@ -78,6 +78,20 @@ func TestZipUrlWithSameEtag(t *testing.T) { require.Equal(t, zus.TargetDirectory, target, "Target directory should be same") } +func TestZipUrlWithBadUrl(t *testing.T) { + _, teardown := setupTests() + defer teardown() + + zus := ZipURLSource{ + URL: "http://notahost.notadomaintoehutoeuhn", + Folder: "/", + Retries: 2, + } + err := zus.Fetch() + defer zus.Close() + require.Error(t, err) +} + func setupTests() (addr string, teardown func()) { // go offline, so we dont invoke npm install for unit tests GoOffline()