Check status code for API
This commit is contained in:
parent
1ee3595767
commit
0adf36d8c2
1 changed files with 4 additions and 0 deletions
4
api.go
4
api.go
|
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue