Check status code for API

This commit is contained in:
Alexander Sheiko 2021-01-05 11:42:51 +02:00
parent 1ee3595767
commit 0adf36d8c2

4
api.go
View file

@ -39,6 +39,10 @@ func (s *Scraper) RequestAPI(req *http.Request, target interface{}) error {
} }
defer resp.Body.Close() defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("response status %s", resp.Status)
}
return json.NewDecoder(resp.Body).Decode(target) return json.NewDecoder(resp.Body).Decode(target)
} }