From 9f2309bd45adc681b2e9eb3ea7fb4955af3a931b Mon Sep 17 00:00:00 2001 From: Evsyukov Denis Date: Sun, 1 Oct 2023 16:39:17 +0300 Subject: [PATCH] fix: process errors on doRequest with exit Closed: #141 --- gobrew.go | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/gobrew.go b/gobrew.go index 8179e47..c6cf651 100644 --- a/gobrew.go +++ b/gobrew.go @@ -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 }