Skip to content

Commit 6a3ff35

Browse files
committed
slurp-url, panics on non-200, non-404 responses.
slurp-url, panics on failing to read response body. these changes ensure that the report will fail to generate rather than generate an incorrect report.
1 parent 81ef485 commit 6a3ff35

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

main.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ func slurp(path string) string {
8888
}
8989

9090
// read the contents at the given `url`.
91-
// returns an empty string on any error.
91+
// 200 responses return the response body.
92+
// 404 responses return an empty string.
93+
// anything else causes a panic.
9294
func slurp_url(url string, token string) string {
9395
client := &http.Client{}
9496
req, _ := http.NewRequest("GET", url, nil)
@@ -101,18 +103,14 @@ func slurp_url(url string, token string) string {
101103
}
102104
defer resp.Body.Close()
103105

104-
if resp.StatusCode != 200 {
105-
if resp.StatusCode != 404 {
106-
stderr("non-200 response from URL: %s (%d)", url, resp.StatusCode)
107-
}
106+
if resp.StatusCode == 404 {
108107
return ""
109108
}
110109

110+
ensure(resp.StatusCode == 200, fmt.Sprintf("non-200, non-404 response from URL: %s (%d)", url, resp.StatusCode))
111+
111112
body, err := io.ReadAll(resp.Body)
112-
if err != nil {
113-
stderr("failed to read URL contents: %s", url)
114-
return ""
115-
}
113+
panicOnErr(err, "reading response body: "+url)
116114
return string(body)
117115
}
118116

0 commit comments

Comments
 (0)