Skip to content

Commit

Permalink
Merge pull request #142 from kevincobain2000/bug141
Browse files Browse the repository at this point in the history
fix: process errors on doRequest with exit
  • Loading branch information
kevincobain2000 authored Oct 6, 2023
2 parents f410516 + 9f2309b commit 987f799
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions gobrew.go
Original file line number Diff line number Diff line change
Expand Up @@ -687,30 +687,25 @@ func doRequest(url string) (data []byte) {
request.Header.Set("User-Agent", "gobrew")

response, err := client.Do(request)
if err != nil {
color.Errorln("==> [Error] Cannot get response:", err.Error())
return
}
utils.CheckError(err, "==> [Error] Cannot get response")

defer func(body io.ReadCloser) {
_ = body.Close()
}(response.Body)

if response.StatusCode == http.StatusTooManyRequests {
if response.StatusCode == http.StatusTooManyRequests ||
response.StatusCode == http.StatusForbidden {
color.Errorln("==> [Error] Rate limit exhausted")
return
os.Exit(1)
}

if response.StatusCode != http.StatusOK {
color.Errorln("==> [Error] Cannot read response:", response.Status)
return
os.Exit(1)
}

data, err = io.ReadAll(response.Body)
if err != nil {
color.Errorln("==> [Error] Cannot read response Body:", err.Error())
return
}
utils.CheckError(err, "==> [Error] Cannot read response Body:")

return
}

0 comments on commit 987f799

Please sign in to comment.