From 0adf36d8c2f1a5b24be5e521a7100034d693441a Mon Sep 17 00:00:00 2001 From: Alexander Sheiko Date: Tue, 5 Jan 2021 11:42:51 +0200 Subject: [PATCH] Check status code for API --- api.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/api.go b/api.go index d9b8635..7b0e1cd 100644 --- a/api.go +++ b/api.go @@ -39,6 +39,10 @@ func (s *Scraper) RequestAPI(req *http.Request, target interface{}) error { } defer resp.Body.Close() + if resp.StatusCode != http.StatusOK { + return fmt.Errorf("response status %s", resp.Status) + } + return json.NewDecoder(resp.Body).Decode(target) }