https://github.com/matryer/httperr
HTTP error wrapper
https://github.com/matryer/httperr
golang http
Last synced: 18 days ago
JSON representation
HTTP error wrapper
- Host: GitHub
- URL: https://github.com/matryer/httperr
- Owner: matryer
- License: mit
- Created: 2019-05-08T14:30:12.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-11-25T17:58:43.000Z (over 5 years ago)
- Last Synced: 2025-03-24T15:11:14.784Z (about 1 month ago)
- Topics: golang, http
- Language: Go
- Size: 18.6 KB
- Stars: 36
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# httperr [](http://godoc.org/github.com/matryer/httperr) [](https://goreportcard.com/report/github.com/matryer/httperr) [](https://travis-ci.org/matryer/httperr)
HTTP error wrapper that returns an error if the HTTP request failed (i.e. 404, 500, etc.) as well as
if any network issues occurred.This is useful for cases when you don't care why an HTTP request failed, and would like to treat
network errors and API errors once.## Usage
```go
req, err := http.NewRequest(http.MethodGet, "/path", nil)
if err != nil {
return errors.Wrap(err, "new request")
}
resp, err := httperr.Check(client.Do(req))
if err != nil {
return errors.Wrap(err, "HTTP error")
}
defer resp.Body.Close()
// use resp
```