Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/matryer/httperr
HTTP error wrapper
https://github.com/matryer/httperr
golang http
Last synced: about 2 months 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 (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-11-25T17:58:43.000Z (about 5 years ago)
- Last Synced: 2024-06-20T05:14:28.626Z (7 months ago)
- Topics: golang, http
- Language: Go
- Size: 18.6 KB
- Stars: 34
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# httperr [![GoDoc](https://godoc.org/github.com/matryer/httperr?status.png)](http://godoc.org/github.com/matryer/httperr) [![Go Report Card](https://goreportcard.com/badge/github.com/matryer/httperr)](https://goreportcard.com/report/github.com/matryer/httperr) [![Build Status](https://travis-ci.org/matryer/httperr.svg?branch=master)](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
```